0
javax.mailパッケージを使用してOutlook 2010から電子メールを送信しようとしていますが、このコードは機能しませんでした。メールとパスワードがスレッド「main」の例外java.lang.RuntimeException:javax.mail.AuthenticationFailedException:535 5.7.3認証に失敗しました
import java.io.IOException;
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 SendMail {
public static void main(String[]args) throws IOException {
final String username = "[email protected]";
final String password = "something";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "outlook.office365.com");
props.put("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("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("Test");
message.setText("HI");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}}
正しいことを確信している、それは私に次のエラーを与えた:
Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
at SendMail.main(SendMail.java:45)
Caused by: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at SendMail.main(SendMail.java:40)
Java Result: 1
これは非常に明白なエラーのための私を許しメールAPIでの作業私の非常に最初の時間です。
なぜOutlookのSMTPサーバを使用してGmailアカウントにログインしていますか? – byxor
男は正気に見えるコードと完全なバックトレースを投稿し、有用なタイトルを付けました。投票を下げる理由はありません。 –
これは私がオンラインで見つけたサンプルコードで、私は電子メールとパスワードを入れれば、それは私に見通しがつくことになると思った。私はこれについて新しく言ったように、私はOutlookの世界に精通していない。だから、どんな助けでも大歓迎です。 – John