简体   繁体   English

javax.mail.MessagingException无法连接到SMTP主机端口:25响应-1

[英]javax.mail.MessagingException could not connect to SMTP host port :25 response -1

I am getting a response code of -1 and I am not sure what is the workaround for this. 我得到的响应代码为-1,我不确定该如何解决。 The office has a firewall setting which cannot be disabled as well as antivirus running.Since the java code is running from the office,how do I get this code working to email the testing report. 办公室的防火墙设置无法禁用,也无法运行防病毒软件。由于java代码是从办公室运行的,因此该代码如何通过电子邮件发送给测试报告。

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@540408: 16 ms
DEBUG: JavaMail version 1.4.5
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
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]}
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]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: setDebug: JavaMail version 1.4.5
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 SMTP: trying to connect to host "xxx.com", port 25, isSSL false
DEBUG SMTP: EOF: [EOF]
DEBUG SMTP: could not connect to host "xxxx.com", port: 25, response: -1

javax.mail.MessagingException: Could not connect to SMTP host: xxx.com, port: 25, response: -1
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1960)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at com.seleniumtests.test.SendFileEmail.trySendEmail(SendFileEmail.java:131)
    at com.seleniumtests.test.Email.generateReport(Email.java:27)
    at org.testng.TestNG.generateReports(TestNG.java:1094)
    at org.testng.TestNG.run(TestNG.java:1053)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

Code to send the email: 发送电子邮件的代码:

Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT );
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
    protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
        return new javax.mail.PasswordAuthentication("myusername","mypassword");
    }
});

From the Java Mail API FAQ : Java Mail API常见问题解答

You should call trans.sendMessage(msg, addrs) to send the message. 您应该调用trans.sendMessage(msg, addrs)发送消息。 As described above, the send method is a static convenience method that acquires its own Transport object and creates its own connection to use for sending; 如上所述, send方法是一种静态便利方法,它获取自己的Transport对象并创建自己的连接以用于发送; it does not use the connection associated with any Transport object through which it is invoked. 它不使用与通过其调用的任何Transport对象关联的连接。

In short, don't call Transport.send(...) , call Transport.sendMessage(...) instead. 简而言之,不要调用Transport.send(...) ,而是调用Transport.sendMessage(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.mail.MessagingException:无法连接到SMTP主机:<主机名>端口:25响应:554 - javax.mail.MessagingException: Could not connect to SMTP host : <host name> port : 25 response: 554 javax.mail.messagingexception无法连接到SMTP主机:主机名端口:25响应:552 - javax.mail.messagingexception could not connect to SMTP host : hostname port:25 response : 552 发送邮件错误,javax.mail.MessagingException:无法连接到SMTP主机:本地主机,端口:25; - Sending mail error, javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; javax.mail.MessagingException:无法连接到SMTP主机:103.12.134.112,端口:25; - javax.mail.MessagingException: Could not connect to SMTP host: 103.12.134.112, port: 25; javax.mail.MessagingException:无法连接到SMTP主机:localhost,端口:25; - javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; javax.mail.MessagingException:无法连接到SMTP主机:172.16.100.185,端口:25; - javax.mail.MessagingException: Could not connect to SMTP host: 172.16.100.185, port: 25; javax.mail.MessagingException:无法连接到 SMTP 主机:本地主机,端口:25 - javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25 邮件服务GAE问题-发送邮件异常“ javax.mail.MessagingException:无法连接到SMTP主机:localhost,端口:25;” - Mail service GAE issue - sending mail exception “javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;” javax.mail.MessagingException:无法连接到 SMTP 主机:email-smtp.us-east-1.amazonaws.com,端口:25; - javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 25; javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.gmail.com,端口:465; - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM