AuthenticationFailedException:[EOF]向SMTP服务器发送未经身份验证的邮件时

AuthenticationFailedException:[EOF]向SMTP服务器发送未经身份验证的邮件时,smtp,jakarta-mail,smtp-auth,Smtp,Jakarta Mail,Smtp Auth,我正在试图弄清楚,当smtp.auth属性设置为false时,为什么会出现AuthenticationFailedException。从调试日志中,它仍然尝试验证登录。我已经针对运行在服务器上的本地主机smtp服务器测试了该代码,该服务器工作正常,但在发送到第三方服务器时失败 我曾尝试通过telnet手动发送电子邮件,但没有使用身份验证,并且电子邮件通过第三方smtp服务器成功发送,因此我不认为这是服务器的限制 我正在使用javamail-1.4.7 调试输出 我不明白为什么它试图验证,即使它被

我正在试图弄清楚,当smtp.auth属性设置为false时,为什么会出现AuthenticationFailedException。从调试日志中,它仍然尝试验证登录。我已经针对运行在服务器上的本地主机smtp服务器测试了该代码,该服务器工作正常,但在发送到第三方服务器时失败

我曾尝试通过telnet手动发送电子邮件,但没有使用身份验证,并且电子邮件通过第三方smtp服务器成功发送,因此我不认为这是服务器的限制

我正在使用javamail-1.4.7

调试输出 我不明白为什么它试图验证,即使它被禁用

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
Oct 18, 2013 11:59:25 PM javax.mail.Session getProvider
FINE: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport protocolConnect
FINE: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "mail.server.com", port 25, isSSL false
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport openServer
FINE: trying to connect to host "mail.server.com", port 25, isSSL false
Oct 18, 2013 11:59:25 PM com.sun.mail.util.SocketFetcher getSocket
FINER: getSocket, host mail.server.com, port 25, prefix mail.smtp, useSSL false
220 ded1081-lin-96-181.server.net ESMTP
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 220 ded1081-lin-96-181.server.net ESMTP
DEBUG SMTP: connected to host "mail.server.com", port: 25

Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport openServer
FINE: connected to host "mail.server.com", port: 25

EHLO menez-bpm.server.com
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: EHLO menez-bpm.server.com
250-ded1081-lin-96-181.server.net
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250-ded1081-lin-69-81.server.net
250-AUTH=LOGIN CRAM-MD5 PLAIN
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250-AUTH=LOGIN CRAM-MD5 PLAIN
250-AUTH LOGIN CRAM-MD5 PLAIN
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250-AUTH LOGIN CRAM-MD5 PLAIN
250-STARTTLS
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250-STARTTLS
250-PIPELINING
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250-PIPELINING
250 8BITMIME
Oct 18, 2013 11:59:25 PM com.sun.mail.util.LogOutputStream log
FINEST: 250 8BITMIME
DEBUG SMTP: Found extension "AUTH=LOGIN", arg "CRAM-MD5 PLAIN"
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport ehlo
FINE: Found extension "AUTH=LOGIN", arg "CRAM-MD5 PLAIN"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN CRAM-MD5 PLAIN"
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport ehlo
FINE: Found extension "AUTH", arg "LOGIN CRAM-MD5 PLAIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport ehlo
FINE: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport ehlo
FINE: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport ehlo
FINE: Found extension "8BITMIME", arg ""
        DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
        Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport authenticate
        FINE: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
Oct 18, 2013 11:59:25 PM com.sun.mail.smtp.SMTPTransport$Authenticator authenticate
FINE: AUTH LOGIN command trace suppressed
DEBUG SMTP: EOF: [EOF]
Oct 18, 2013 11:59:26 PM com.sun.mail.smtp.SMTPTransport readServerResponse
FINE: EOF: [EOF]
DEBUG SMTP: AUTH LOGIN failed
Oct 18, 2013 11:59:26 PM com.sun.mail.smtp.SMTPTransport$Authenticator authenticate
FINE: AUTH LOGIN failed
javax.mail.AuthenticationFailedException: [EOF]
    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
    at javax.mail.Service.connect(Service.java:295)
    at com.compressus.medx.domain.service.AlertDomainService.sendEmailNotification(AlertDomainService.java:324)
    at com.compressus.medx.domain.service.AlertDomainService.sendEmailNotification(AlertDomainService.java:224)
    at com.compressus.medx.domain.service.UserDomainService.sendEmailNotificationByRole(UserDomainService.java:377)
    at com.compressus.medx.domain.service.MailTest.main(MailTest.java:38)
[ERROR] Bad credentials or smtp server information supplied. Check configuration. [Ljava.lang.StackTraceElement;@394b394b
代码 请注意,尽管mail.smtp.auth默认为false,但我尝试显式声明它,但仍然没有帮助

MailServer mailServer = MailServer.getInstance();

if (mailServer != null)
{

    Properties mailProps = new Properties();

    mailProps.put("mail.smtp.host", mailServer.getSmtpServer());
    mailProps.put("mail.smtp.port", mailServer.getSmtpPort());
    //mailProps.put("mail.smtp.auth.login.disable", "true");
    //mailProps.put("mail.smtp.auth", "false");
    mailProps.put("mail.debug", "true");
    /*
     * Authentication is true if the email account name is set.
     */

    if (mailServer.getSmtpAccount() != null && !mailServer.getSmtpAccount().equals(""))
    {
    mailProps.put("mail.smtp.auth", "true");
    //mailProps.put("mail.smtp.auth.login.disable", "false");
    mailProps.put("mail.smtp.auth.user", mailServer.getSmtpAccount());
    mailProps.put("mail.smtp.auth.password", mailServer.getSmtpPassword());
    }

    if (mailServer.getSmtpEncryptionType().equals("TLS"))
    {
    mailProps.put("mail.smtp.starttls.enable", "true");
    }
    else if (mailServer.getSmtpEncryptionType().equals("SSL"))
    {
    mailProps.put("mail.smtp.socketFactory.port", mailServer.getSmtpPort());
    mailProps.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    }

    try
    {
    Session session = Session.getInstance(mailProps);

    // create a message
    Message msg = new MimeMessage(session);
    // msg.setFrom(new InternetAddress(from));
    // log.debug("setting from ... success:" + from);
    InternetAddress[] addresses = null;

    String[] addressList = toUserEmailAddress.split(",");
    addresses = new InternetAddress[addressList.length];
    for (int i = 0; i < addressList.length; i++)
        addresses[i] = new InternetAddress(addressList[i]);

    msg.setRecipients(Message.RecipientType.BCC, addresses);
    msg.setSubject(subjectText);
    msg.setSentDate(new java.util.Date());

    if (from == null || from.trim().equals(""))
    {
        msg.setFrom(new InternetAddress("no-reply@compressus.com", "MEDxConnect"));
    }
    else
    {
        msg.setFrom(new InternetAddress("no-reply@compressus.com", from));
    }

    Multipart mainPart = new MimeMultipart();
    // Add body to the email
    BodyPart bodyTextPart = new MimeBodyPart();
    bodyTextPart.setContent(bodyText, "text/html");
    mainPart.addBodyPart(bodyTextPart);

    // add attachment to the email
    if (attachmentPath != null && !attachmentPath.isEmpty())
    {
        BodyPart attachPart = new MimeBodyPart();
        FileDataSource fds = new FileDataSource(attachmentPath);
        attachPart.setDataHandler(new DataHandler(fds));
        attachPart.setFileName(fds.getName());
        attachPart.setHeader("Content-Type", "application/pdf");
        attachPart.setHeader("Content-Transfer-Encoding", "BASE64");
        mainPart.addBodyPart(attachPart);
    }
    msg.setContent(mainPart);
    Transport transport;
    if (!mailServer.getSmtpEncryptionType().equals("None"))
        transport = session.getTransport("smtps");
    else
        transport = session.getTransport("smtp");
    transport.connect(mailServer.getSmtpServer(), mailServer.getSmtpPort(), mailServer.getSmtpAccount(), mailServer.getSmtpPassword());

    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    log.info("Mail " + subjectText + " sent to " + toUserEmailAddress);
    retValue = true;
    }
    catch (AuthenticationFailedException authEx)
    {
    java.util.logging.Logger l = java.util.logging.Logger.getLogger(AlertDomainService.class.getName());
    l.setLevel(Level.FINEST);
    log.error("Bad credentials or smtp server information supplied. Check configuration. " + authEx.getStackTrace());
    }
    catch (Exception ex)
    {
    log.error("Error occurred while sending email: " + ex);

    do
    {
        if (ex instanceof SendFailedException)
        {
        String errormsg = "";
        SendFailedException sfex = (SendFailedException) ex;
        Address[] invalid = sfex.getInvalidAddresses();
        if (invalid != null && invalid.length > 0)
        {
            errormsg = "Invalid Addresses: ";
            for (int i = 0; i < invalid.length; i++)
            {
            errormsg += invalid[i] + " ";

            }
            log.error(errormsg);
        }
        Address[] validUnsent = sfex.getValidUnsentAddresses();
        if (validUnsent != null && validUnsent.length > 0)
        {
            errormsg = "ValidUnsent Addresses: ";

            for (int i = 0; i < validUnsent.length; i++)
            {
            errormsg += validUnsent[i] + " ";

            }
            log.error(errormsg);

        }
        Address[] validSent = sfex.getValidSentAddresses();
        if (validSent != null && validSent.length > 0)
        {
            errormsg = "ValidSent Addresses: ";

            for (int i = 0; i < validSent.length; i++)
            {
            errormsg += validSent[i] + " ";

            }
            log.error(errormsg);

        }
        }
        if (ex instanceof MessagingException)
        {
        ex = ((MessagingException) ex).getNextException();
        }
        else
        {
        ex = null;
        }
    } while (ex != null);
    }
}
else
{
    log.error("No mail server information found. Email notification aborted");
}
MailServer-MailServer=MailServer.getInstance();
if(mailServer!=null)
{
Properties mailProps=新属性();
mailProps.put(“mail.smtp.host”,mailServer.getSmtpServer());
mailProps.put(“mail.smtp.port”,mailServer.getSmtpPort());
//mailProps.put(“mail.smtp.auth.login.disable”、“true”);
//mailProps.put(“mail.smtp.auth”、“false”);
mailProps.put(“mail.debug”,“true”);
/*
*如果设置了电子邮件帐户名,则验证为true。
*/
如果(mailServer.getSmtpAccount()!=null&&!mailServer.getSmtpAccount()等于(“”)
{
mailProps.put(“mail.smtp.auth”,“true”);
//mailProps.put(“mail.smtp.auth.login.disable”、“false”);
mailProps.put(“mail.smtp.auth.user”,mailServer.getSmtpAccount());
mailProps.put(“mail.smtp.auth.password”,mailServer.getSmtpPassword());
}
if(mailServer.getSmtpEncryptionType().equals(“TLS”))
{
mailProps.put(“mail.smtp.starttls.enable”,“true”);
}
else if(mailServer.getSmtpEncryptionType().equals(“SSL”))
{
mailProps.put(“mail.smtp.socketFactory.port”,mailServer.getSmtpPort());
put(“mail.smtp.socketFactory.class”,“javax.net.ssl.SSLSocketFactory”);
}
尝试
{
Session=Session.getInstance(mailProps);
//创建消息
Message msg=新的mimessage(会话);
//msg.setFrom(新因特网地址(from));
//调试(“设置从…成功:+from”);
InternetAddress[]地址=空;
String[]addressList=toUserEmailAddress.split(“,”);
地址=新的InternetAddress[addressList.length];
for(int i=0;i0)
{
errormsg=“无效地址:”;
for(int i=0;i0)
{
errormsg=“ValidUnsent地址:”;
for(int i=0;i0)
{
errormsg=“有效地址:”;
for(int i=0;iif(mail.smtp.auth is set to false)
{
    m_transport.connect(new Socket(getSMTPHost, getSMTPPort));
)else{
    m_transport.connect(SMTPHost,SMTPPort,AuthUserAddress,Password);
}