必须首先发出 STARTTLS 命令。 使用 Java 和 Google Apps 发送电子邮件
我正在尝试使用 比尔蜥蜴代码以使用 Google Apps 发送电子邮件。 我收到此错误:
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. f3sm9277120nfh.74
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:81)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:44)
比尔的代码包含下一行,这似乎与错误相关:
props.put("mail.smtp.starttls.enable","true");
但是,它没有帮助。
这些是我的导入语句:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
有人知道这个错误吗?
I am trying to use Bill the Lizard's code to send an email using Google Apps. I am getting this error:
Exception in thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. f3sm9277120nfh.74
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:81)
at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:44)
Bill's code contains the next line, which seems related to the error:
props.put("mail.smtp.starttls.enable","true");
However, it does not help.
These are my import statements:
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
Does anyone know about this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我发现了问题。 以前我使用 j2ee.jar 导入 javax.mail。
我从类路径中删除了 j2ee.jar 并下载了 JavaMail 1.4.1 并将其放入我的类路径二jars、smtp.jar 和 mailapi.jar。 我现在使用 smtps 而不是 smtp
现在 Bill the Lizard 的代码可以工作了。
I found the problem. Previously i was using j2ee.jar to import javax.mail.
I removed j2ee.jar from the classpath and downloaded JavaMail 1.4.1 and put into my classpath two jars, smtp.jar and mailapi.jar. I use now smtps instead smtp
Now Bill the Lizard's code works.
设置以下标签。 它会起作用的。
Set the following tags. It will work.
这是java邮件API的版本。
我遇到了这个问题,我刚刚将 java mail API 更新到 1.4.3
这对我来说可以!
谢谢!
It is the version of java mail API.
I was facing this issue and I just updated the java mail API to 1.4.3
It works fine for me!
Thanks!
我认为这与使用 SMTPS 而不是 SMTP 进行邮件传输有关。 这是一个不同的版本,以有关访问 Gmail 的 JavaMail 常见问题解答为蓝本。 请注意,为了清楚起见,我省略了所有更精细级别的异常处理。
I think it's got to do with using SMTPS instead of SMTP for mail transport. Here's a different version, modeled after the JavaMail FAQ on accessing Gmail. Note that I have left out all of the finer level exception handling for clarity.
这让我发疯,所以只想添加对我有用的东西。 我必须更新我的 JavaMail 版本(1.4.5)才能正常工作 - 不确定之前使用的是哪个版本。
当我更新到新版本的 JavaMail 后,以下代码对我有用(可以取消注释调试行以获取其他调试信息 - 端口为 587,主机为 smtp.gmail.com)代码>):
This was driving me crazy and so just wanted to add what worked for me. I had to update my version of JavaMail (1.4.5) for this to work - not sure what version was being used before.
Once I updated to new version of JavaMail, the following code worked for me (can uncomment the debug lines to get additional debugging info - port was
587
and host wassmtp.gmail.com
):试试这个:
开启:允许您的 Gmail 帐户使用不太安全的应用
https://myaccount.google.com/lesssecureapps< /a>
try this:
turn on: Allow less secure apps for your gmail account
https://myaccount.google.com/lesssecureapps