本文介绍了javax.mail.MessagingException:无法连接到SMTP主机:email-smtp.us-east-1.amazonaws.com,端口:25;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

公共无效的emailTest(){

public void emailTest() {

    Properties properties=new Properties();
    properties.put("mail.smtp.host", "email-smtp.us-east-1.amazonaws.com");
    properties.put("mail.smtp.port", 587);
    properties.put("mail.debug", "true");
    try{
    Session session=Session.getInstance(properties);

    Message msg=new MimeMessage(session);

    msg.setFrom(new InternetAddress("[email protected]", "Test"));
    msg.setRecipient(RecipientType.TO, new InternetAddress("[email protected]", "Test"));
    msg.setSubject("Test Subject");
    msg.setText("Test Mail");
    msg.saveChanges();
    Transport transport=session.getTransport("smtp");
    transport.connect("username","password");
    transport.sendMessage(msg, msg.getAllRecipients());

    transport.close();

    }catch(Exception e){
        e.printStackTrace();
    }
}

POM:com.sun.mail javax.mail 1.5.2已提供

POM : com.sun.mail javax.mail 1.5.2 provided

调试:JavaMail版本1.4ea

DEBUG: JavaMail version 1.4ea

调试:java.io.FileNotFoundException:/usr/java/jdk1.8.0_144/jre/lib/javamail.providers(无此类文件或目录)

DEBUG: java.io.FileNotFoundException: /usr/java/jdk1.8.0_144/jre/lib/javamail.providers (No such file or directory)

调试:!anyLoaded

DEBUG: !anyLoaded

调试:未加载资源:/META-INF/javamail.providers

DEBUG: not loading resource: /META-INF/javamail.providers

调试:已成功加载资源:/META-INF/javamail.default.providers

DEBUG: successfully loaded resource: /META-INF/javamail.default.providers

调试:已加载的提供程序表

DEBUG: Tables of loaded providers

调试:按类名称列出的提供程序:{com.sun.mail.smtp.SMTPSSLTransport = javax.mail.Provider [TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems,Inc],com. sun.mail.smtp.SMTPTransport = javax.mail.Provider [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems,Inc],com.sun.mail.imap.IMAPSSLStore = javax.mail.Provider [ STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems,Inc],com.sun.mail.pop3.POP3SSLStore = javax.mail.Provider [STORE,pop3s,com.sun.mail.pop3.POP3SSLStore, 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 Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,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]}

调试:按协议列出的提供程序:{imaps = javax.mail.Provider [STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems,Inc],imap = javax.mail.Provider [STORE,imap ,com.sun.mail.imap.IMAPStore,Sun Microsystems,Inc],smtps = javax.mail.Provider [TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems,Inc],pop3 = javax.mail .Provider [STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems,Inc],pop3s = javax.mail.Provider [STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems,Inc] ,smtp = javax.mail.Provider [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems,Inc]]

DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}

调试:已成功加载资源:/META-INF/javamail.default.address.map

DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map

调试:!anyLoaded

DEBUG: !anyLoaded

调试:未加载资源:/META-INF/javamail.address.map

DEBUG: not loading resource: /META-INF/javamail.address.map

调试:java.io.FileNotFoundException:/usr/java/jdk1.8.0_144/jre/lib/javamail.address.map(无此类文件或目录)

DEBUG: java.io.FileNotFoundException: /usr/java/jdk1.8.0_144/jre/lib/javamail.address.map (No such file or directory)

调试:getProvider()返回javax.mail.Provider [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems,Inc]

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

调试SMTP:useEhlo为true,useAuth为false

DEBUG SMTP: useEhlo true, useAuth false

调试SMTP:尝试连接到主机"email-smtp.us-east-1.amazonaws.com",端口25,isSSL为假

DEBUG SMTP: trying to connect to host "email-smtp.us-east-1.amazonaws.com", port 25, isSSL false

推荐答案

您使用的是JavaMail的较旧版本;请尽可能进行更新.

You're using an ancient version of JavaMail; please update if possible.

如果您正在AWS中运行JavaMail程序,请注意AWS关于如何使用JavaMail和可以使用的SMTP主机有限制连接到.有关详细信息,请查阅其文档. (对不起没有链接.)

If you're running your JavaMail program within AWS, note that AWShas restrictions on how you use JavaMail and what SMTP host you canconnect to. Consult their documentation for details. (Sorry, Idon't have the link.)

如果您在AWS之外运行,请参阅JavaMail FAQ,以获取提示调试连接问题.您很可能在防火墙后面,阻止您直接连接.

If you're running outside of AWS, see the JavaMail FAQ for tips ondebugging connection problems. Most likely you're behind a firewall that's preventing you from connecting directly.

这篇关于javax.mail.MessagingException:无法连接到SMTP主机:email-smtp.us-east-1.amazonaws.com,端口:25;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:55