获取问题com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令

时间:2016-07-31 05:10:53

标签: java smtp javamail

获取问题com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须先发出STARTTLS命令 试图从我的程序发送电子邮件到任何电子邮件。它是一个从教程中取得的一个例子,但我不能运行这个例子。响应是com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令

package test;
import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import java.util.Properties;

public class Main {
  public static void main(String[] args) throws MessagingException {
    String from = "user@some-domain.com";
    String to = "muhammadabdullah0008@gmail.com";
    String subject = "Hi There...";
    String text = "How are you?";

    Properties properties = new Properties();
    properties.put("mail.smtp.host", "smtp.gmail.com");
    properties.put("mail.smtp.port", "25");
    Session session = Session.getDefaultInstance(properties, null);

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(text);

    Transport.send(message);
  }
}

这是输出enter image description here

0 个答案:

没有答案