我使用 SMTP 发送电子邮件时出现错误。我的身份验证失败。用户名和密码正确。难道我做错了什么。
public class Office365TextMsgSend {
Properties properties;
Session session;
MimeMessage mimeMessage;
String USERNAME = "xxxx@xxxx.xx";
String PASSWORD = "xxxxxxx";
String HOSTNAME = "smtp.office365.com";
String STARTTLS_PORT = "587";
boolean STARTTLS = true;
boolean AUTH = true;
String FromAddress="xxxx@xxxx.xx";
public static void main(String args[]) throws MessagingException {
String EmailSubject = "Subject:Text Subject";
String EmailBody = "Text Message Body: Hello World";
String ToAddress = "xxxxxx@gmail.com";
Office365TextMsgSend office365TextMsgSend = new Office365TextMsgSend();
office365TextMsgSend.sendGmail(EmailSubject, EmailBody, ToAddress);
}
public void sendGmail(String EmailSubject, String EmailBody, String …
Run Code Online (Sandbox Code Playgroud)