【发布时间】:2012-05-09 04:09:35
【问题描述】:
我正在使用我的Gmail 帐户运行这个简单的示例,但它不起作用并出现以下错误:
send failed, exception: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. nv2sm4478384pbb.6
这是我的代码
public class Email
{
public static void main(String [] args)
{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.googlemail.com");
props.put("mail.from", "myemail@gmail.com");
Session session = Session.getInstance(props, null);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
"myemail@hotmail.com");
msg.setSubject("JavaMail hello world example");
msg.setSentDate(new Date());
msg.setText("Hello, world!\n");
Transport.send(msg);
} catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
}
}
【问题讨论】:
-
必须先发出 STARTTLS 命令。 nv2sm4478384pbb.6
-
您需要添加以下行:props.put("mail.smtp.starttls.enable", "true");
-
在这里查看我的答案:stackoverflow.com/questions/26774057/… 也许会有所帮助
标签: java