gpt4 book ai didi

JavaMail - 客户端未经过身份验证,无法在 MAIL FROM 期间发送匿名邮件

转载 作者:行者123 更新时间:2023-12-02 04:47:12 25 4
gpt4 key购买 nike

我正在尝试使用JavaMail通过office365有效帐户发送电子邮件。但是,我收到相同的异常 '530 5.7.57 SMTP;客户端未经过身份验证,无法在 MAIL FROM' 期间发送匿名邮件。按照我用于测试的简单代码:

Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.office365.com");
props.put("mail.smtp.port", "587");
props.put("mail.debug", "true");

Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(USER_NAME, USER_PASS);
}
});

try {
final Message message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO, new InternetAddress(USER_NAME));
message.setFrom(new InternetAddress(USER_NAME));
message.setSubject(subject);
message.setText(messageContent);
message.setSentDate(new Date());
Transport.send(message);
System.out.println("Send OK");
} catch (final MessagingException ex) {
System.out.println(ex.getMessage());
}

调试输出如下:

DEBUG: JavaMail version 1.3
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_171\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.8.0_171\lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true

DEBUG: SMTPTransport trying to connect to host "smtp.office365.com", port 587

DEBUG SMTP RCVD: 220 xxxxx.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 6 Jun 2019 07:53:32 +0000

DEBUG: SMTPTransport connected to host "smtp.office365.com", port: 587

DEBUG SMTP SENT: EHLO L3343005201
DEBUG SMTP RCVD: 250-xxxxx.outlook.office365.com Hello [92.242.173.14]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8

DEBUG SMTP Found extension "SIZE", arg "157286400"
DEBUG SMTP Found extension "PIPELINING", arg ""
DEBUG SMTP Found extension "DSN", arg ""
DEBUG SMTP Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP Found extension "STARTTLS", arg ""
DEBUG SMTP Found extension "8BITMIME", arg ""
DEBUG SMTP Found extension "BINARYMIME", arg ""
DEBUG SMTP Found extension "CHUNKING", arg ""
DEBUG SMTP Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<sender@domain>
DEBUG SMTP RCVD: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxx.yyyyy.outlook.com]

DEBUG SMTP SENT: QUIT
Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxx.yyyyy]

从日志来看,身份验证似乎不起作用,并且连接端口变为 25,而不是属性中指定的 587。

我也尝试添加其他属性,例如

props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.user", USER_NAME);
props.put("mail.smtp.password", USER_PASS);
props.put("mail.smtp.from", USER_NAME);

任意组合,但没有结果。我也尝试过使用 JavaMail 库的更新版本,但异常(exception)情况是相同的。我是否缺少邮件帐户的任何配置?或者来自代码?

提前致谢

已编辑:将端口从 587(int)更改为“587”(字符串)解决了调试端口中的端口问题,但出现了相同的客户端身份验证错误

最佳答案

JavaMail 1.3 已经 17 岁了!你在哪里找到它?切换到current release然后修复所有这些common JavaMail mistakes .

关于JavaMail - 客户端未经过身份验证,无法在 MAIL FROM 期间发送匿名邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56473497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com