- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个在 Openshift Free (redhat webhotel) 上运行的网络应用程序。
从这个应用程序中,我想通过我的 gmail 帐户使用 javax.mail-api 发送一封电子邮件。
当我尝试从我的开发人员机器运行我的代码尝试时,它在使用 SSL 和不使用 SSL 时都可以正常工作。
但是当我从 openshift 服务器中的 JSP 页面运行它时,它不起作用。我从 gmail 得到这个回复:
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbs0N
534-5.7.14 -wfEXm3iqKdenfgsums1_oLzBr3toWk44lKCVSpdKHkI2cJpo5ytmXFAU2LVn_4a3wrT-2
534-5.7.14 YUjbzlo4QJZRTxuWxujUOMJW8m5HMbUgHqZp0cBWjGZH-Nr5CZrHql_uZx_6IaEot3NJ-m
534-5.7.14 pBj85PCczPqx2q7NFQ6faPMgDRp7yEXlDAKOEZZ10gjxhQ3NLGFYV-_n9yS2ae49ZQOFHn
534-5.7.14 VTLSwBg> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 g4sm1374527qas.22 - gsmtp
public static void sendGmail(String to, String subject, String text) throws AddressException, MessagingException
{
final String SMTP_HOST = "smtp.gmail.com";
final String SMTP_PORT = "587";
final String GMAIL_USERNAME = "xxx@gmail.com";
final String GMAIL_PASSWORD = "xxx";
System.out.println("Process Started");
Properties prop = System.getProperties();
prop.setProperty("mail.smtp.starttls.enable", "true");
prop.setProperty("mail.smtp.host", SMTP_HOST);
prop.setProperty("mail.smtp.user", GMAIL_USERNAME);
prop.setProperty("mail.smtp.password", GMAIL_PASSWORD);
prop.setProperty("mail.smtp.port", SMTP_PORT);
prop.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(prop, new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(GMAIL_USERNAME,
GMAIL_PASSWORD);
}
});
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(GMAIL_USERNAME));
message.addRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
message.setSubject(subject);
message.setText(text);
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
Transport transport = session.getTransport("smtp");
transport.connect(SMTP_HOST, GMAIL_USERNAME, GMAIL_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
}
public static void sendGmail(String to, String subject, String text) throws AddressException, MessagingException
{
String host = "smtp.gmail.com";
final String GMAIL_USERNAME = "xxx@gmail.com";
final String GMAIL_PASSWORD = "xxx";
Properties props = new Properties();
props.put("mail.smtps.host", host);
props.put("mail.smtps.auth", "true");
Session session = Session.getInstance(props, null);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setSubject(subject);
msg.setText(text);
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setFrom(new InternetAddress(username));
msg.setHeader("X-Mailer", "smtpsend");
msg.setSentDate(new Date());
SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
try
{
t.connect(host, username, password);
t.sendMessage(msg, msg.getAllRecipients());
}
finally
{
t.close();
}
}
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 mx.google.com ESMTP ny6sm229296lbb.2 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<xxx@gmail.com>
250 2.1.0 OK ny6sm229296lbb.2 - gsmtp
RCPT TO:<xxx@hotmail.com>
250 2.1.5 OK ny6sm229296lbb.2 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: xxx@hotmail.com
DATA
354 Go ahead ny6sm229296lbb.2 - gsmtp
Date: Tue, 4 Nov 2014 15:23:48 +0100 (CET)
From: xxx@gmail.com
To: xxx@hotmail.com
Message-ID: <30266940.0.1415111029890.JavaMail.RPS@fredand>
Subject: Subject_Tue Nov 04 15:23:48 CET 2014
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: smtpsend
text_Tue Nov 04 15:23:48 CET 2014
.
250 2.0.0 OK 1415111029 ny6sm229296lbb.2 - gsmtp
QUIT
221 2.0.0 closing connection ny6sm229296lbb.2 - gsmtp
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 mx.google.com ESMTP 4sm1230842qax.48 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsvV
534-5.7.14 5K74amuA1WqDS9CFS1UPmuS3XUVU7lq0Agwb5DPcG69Z5fkYe6RUZrzAKPDWy9tQzq2BDg
534-5.7.14 1AxC2MmT1D1UXOXLG8cZuf7yKxKEUtaLo79a-fROXRiwCvMaqdvYXhqiIslXDTWJQZVe5W
534-5.7.14 qYvj9_ov5cziZe3ao5usZ-o58tHCv48yzrRm5SppAESXnvmv35ZLy4U9qF14GLEXHT7Wzj
534-5.7.14 QuIfn6w> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 4sm1230842qax.48 - gsmtp
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 mx.google.com ESMTP x6sm542099lbj.40 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO fredand
250-mx.google.com at your service, [90.230.21.163]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<xxx@gmail.com>
250 2.1.0 OK x6sm542099lbj.40 - gsmtp
RCPT TO:<xxx@hotmail.com>
250 2.1.5 OK x6sm542099lbj.40 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: xxx@hotmail.com
DATA
354 Go ahead x6sm542099lbj.40 - gsmtp
From: xxx@gmail.com
To: xxx@hotmail.com
Message-ID: <27966883.0.1415135485593.JavaMail.RPS@fredand>
Subject: Subject_Tue Nov 04 22:11:24 CET 2014
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
text_Tue Nov 04 22:11:24 CET 2014
.
250 2.0.0 OK 1415135486 x6sm542099lbj.40 - gsmtp
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.4]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 mx.google.com ESMTP g4sm1374527qas.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO ex-std-node449.prod.rhcloud.com
250-mx.google.com at your service, [54.90.46.53]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
bm9ycnVkZGVuLnZhZ2ZvcmVuaW5nQGdtYWlsLmNvbQ==
334 UGFzc3dvcmQ6
bm9ycnVkZGVuOTc=
534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbs0N
534-5.7.14 -wfEXm3iqKdenfgsums1_oLzBr3toWk44lKCVSpdKHkI2cJpo5ytmXFAU2LVn_4a3wrT-2
534-5.7.14 YUjbzlo4QJZRTxuWxujUOMJW8m5HMbUgHqZp0cBWjGZH-Nr5CZrHql_uZx_6IaEot3NJ-m
534-5.7.14 pBj85PCczPqx2q7NFQ6faPMgDRp7yEXlDAKOEZZ10gjxhQ3NLGFYV-_n9yS2ae49ZQOFHn
534-5.7.14 VTLSwBg> Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 g4sm1374527qas.22 - gsmtp
最佳答案
感谢所有帮助。
似乎我需要在我的 gmail 帐户中激活 IMAP。
之后它工作得很好。
此致
弗雷德里克
关于email - 如何从openshift服务器内部通过gmail-account使用javamail发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765696/
在发布之前,我在互联网上阅读了很多内容和建议的问题,但找不到任何适合我的内容。 有关使用 gmail 的 JavaMail 常见问题解答 Stackoverflow 问题 JavaMail 教程 Go
我正在尝试通过 java 邮件发送电子邮件。它给出了以下异常javax.mail.internet.ParseException: 在 Content-Type string 中,预期的 MIME 类
我想从我的 Gmail 帐户的特定文件夹中获取最近未读的具有特定主题的电子邮件。我正在使用 JavaMail API,如下所示,但它返回 0 个结果。但是,如果我只单独使用 subjectTerm,我
我正在开发一个基于 Spring 的网络应用程序,当用户输入他的电子邮件和密码进行注册时我想验证它们并向他发送电子邮件。我已经使用 java mail api并正确设置gmail smtp。 这是我的
我试图获取我的 Gmail 的所有邮件,但只能获取 250 封。根据 https://javaee.github.io/javamail/FAQ#gmailsettings ,我已经将邮件数量限制设置
我有几封主题为报告 #123:来自测试的“Email_test_856” 的电子邮件。我尝试使用 JavaMail API 根据关键字 Email_test 查找邮件,但它不会过滤掉任何邮件。 这是我
我有一种方法可以发送 HTML 电子邮件和嵌入的图片,以引用我的计算机中的图像,例如 c:/image.gif 该方法效果很好,但我不知道如何添加位于远程计算机中的图像,我知道您的 IP 地址和图像所
这是我的代码,它应该会收到未读消息。然而,它正在返回我收件箱中的最后一条消息。有什么建议吗? import javax.mail.*; import javax.mail.internet.*; im
Javax邮件版本使用1.6.2 手动设置 JavaMailSender 我尝试使用 mail.smtp.timeout 和 mail.smtps.timeout 超时。 而且,我尝试使用字符串和整数
我有以下问题:我的电子邮件客户端使用 Javamail,可以获取电子邮件的所有部分,如发送日期、主题、发件人、收件人等,但我不知道如何获取邮件正文. 我已经尝试过 getContent() 函数,但它
我编写了一个使用 JavaMail API 发送 gmail 的程序。以下是我的代码: import java.util.*; import javax.mail.*; import javax.ac
所以我的问题是关于JavaMail 的。我想向不同的电子邮件地址发送电子邮件,但我希望发件人类似于“noreply”。但是,我似乎无法这样做,因为 JavaMail 需要发送者和接收者都有实际的电子邮
我正在尝试从 Java 应用程序发送电子邮件,但每当我运行在线找到的代码时 here 当我运行代码时,我收到此错误: Exception in thread "main" java.lang.NoCl
所以我遇到了 Javamail 的问题,如果我在邮件中发送附件,正文就会消失。当我不随邮件发送附件时,我只能看到正文。 我的 GMailSender.java: public GMailSender(
我有一个关于 Java Mail 及其如何与流配合使用的问题。在 Java Mail 1.4.1 中,有一个 MimeMessage constructor that accepts a stream
我窃取了这段代码来测试使用 java 发送电子邮件的情况。显然,Javamail 是必需的。由于某种原因,我无法实现 javax.mail。我下载了最新的javamail并将它们放入jdk和jre l
我正在使用 JavaMail 开发一个邮件客户端,它运行良好。现在我希望能够处理传入消息的已读回执。如果传入的邮件 header 包含“Disposition-Notification-To”,我想处
Javamail 在 JUnit 测试和 GlassFish 3.1.2 中工作正常,但在 Tomcat 7.0.41 中不起作用:所有“From” header 均为 NULL!我究竟做错了什么?当
我尝试使用 javamail 连接到电子邮件 - 在非 Android 应用程序中,此代码工作正常: public void perform(View v){ Toast.makeText(g
我必须向多个收件人发送电子邮件。我不希望标题显示完整的收件人列表(即我没有使用“Message.RecipientType.CC”)。如果我使用“Message.RecipientType.BCC”,
我是一名优秀的程序员,十分优秀!