我正在通过 android 上的 o-auth 应用程序制作 gmail。
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.sasl.enable", "true");
props.put("mail.smtp.sasl.mechanisms", "XOAUTH2");
props.put("mail.smtp.sasl.mechanisms.oauth2.oauthToken", oAuthToken);
Session session = Session.getInstance(props);
SMTPTransport transport = new SMTPTransport(session, null);
transport.connect("smtp.gmail.com", 587, "send-addr@gmail.com", null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("send-addr@gmail.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("dest-addr@example.com"));
msg.setSubject("test");
msg.setText("hi!");
transport.sendMessage(message, InternetAddress.parse("send-addr@gmail.com"));
此代码 [transport.connect(..] 成功,但 [transport.sendMessage(..] 失败。
com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 in2sm6968052pbc.37 - gsmtp
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
这段代码有什么问题?