我正在尝试编写一个简单的Java程序,使用JavaMailAPI从我的hotmail帐户发送电子邮件。这是我的代码:
import java.util.Properties;
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;
public class HotMailSend {
public static void main(String args[])
{
final String username = HOTMAIL.username;
final String password = HOTMAIL.password;
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.host", "smtp.live.com");
props.setProperty("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(HOTMAIL.username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(GMAIL.username));
message.setSubject("Testing Subject");
message.setText("Hey Buddy..!!!,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
这是我得到的错误:
我以前在Hotmail中使用过SMTP/Javamail,所以它肯定有效。你在短时间内发送了很多电子邮件吗?(我认为当你这样做时,作为垃圾邮件预防措施,他们可能会阻止你的邮件或将其发送到垃圾文件夹。)
检查您当前使用的电子邮件是否收到来自microsoft的消息。
与我发生了这个问题,当我寻找它,我有一个电子邮件,有以下主题:验证您的帐户做更多的Outlook.com。
他们让我确认我真的是一个人,这样我就可以继续发送自动消息。他们给我的手机发了一条信息,我设法继续用Java邮件发送电子邮件。