问题描述
我正在尝试使用 使用 Google Apps 向 Lizard 的代码收费发送电子邮件.我收到此错误:
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 的代码包含下一行,似乎与错误有关:
Bill's code contains the next line, which seems related to the error:
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;
有人知道这个错误吗?
推荐答案
我发现了问题.以前我使用 j2ee.jar 导入 javax.mail.
I found the problem. Previously i was using j2ee.jar to import javax.mail.
我从类路径中删除了 j2ee.jar 并下载了 JavaMail 1.4.1 并放入我的类路径有两个 jar,smtp.jar 和 mailapi.jar.我现在用 smtps 而不是 smtp
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
Transport transport = session.getTransport("smtps");
现在比尔蜥蜴的代码有效.
Now Bill the Lizard's code works.
这篇关于必须首先发出 STARTTLS 命令.使用 Java 和 Google Apps 发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!