必须先发出STARTTLS命令

我正在使用我的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);

}

}

}

回答:

您可能正在尝试使用端口25上的Gmail服务器通过未经身份验证的连接将邮件传递给第三方。Gmail不允许您这样做,因为这样 任何人

都可以使用Gmail的服务器将邮件发送给其他任何人。这称为 开放中继 ,在早期是垃圾邮件的常见促成因素。Internet上不再接受开放中继。

您将需要让SMTP客户端使用经过身份验证的连接(可能在端口587上)连接到Gmail

以上是 必须先发出STARTTLS命令 的全部内容, 来源链接: utcz.com/qa/402341.html

回到顶部