简体   繁体   中英

Simple Java Mail API: Mail queue for send but did not receive any email

I writing a email client using simple java mail API and it queue for sending but I did not receive any email.

Execution Info:

INFO: SESSION[1] bridging to remote proxy http://10.64.150.9:8080 , username: kwong@who.int, proxy bridge @ localhost:1081

My Code:

public void sendEmail() {
        try {
            init();
            DataSource fileData = new FileDataSource(new File(".\\report\\Test-Report.html"));

            Email aEmail = EmailBuilder.startingBlank()
                    .from("Peter Wong", "peterapiit@gmail.com")
                    .to(recipientList)
                    .withSubject("ePQS Automation Testing Report")
                    .withPlainText("Please find the ePQS Automation Testing Report from attachment")
                    .withAttachment("ePQS Automation Test Report", fileData)
                    .withBounceTo("kwong@who.int")
                    .buildEmail();

            Mailer mailer = MailerBuilder
                    .withSMTPServer("smtp.gmail.com", 587, "peterapiit@gmail.com", "1234")
                    .withTransportStrategy(TransportStrategy.SMTP_TLS)
                    .withProxy("http://10.64.150.9", 8080, "kwong@who.int", crypt.decryptPwd(".\\password\\peter_wong_wims.txt"))
                    .withSessionTimeout(10 * 1000)
                    .clearEmailAddressCriteria() // turns off email validation
                    .withDebugLogging(true)
                    .buildMailer();

            mailer.sendMail(aEmail, true);

        } catch (Exception ex) {
            LogManager.logger.log(Level.INFO, "Exception: " + ex.getMessage());
        }

    }

I"m behind corporate proxy and connect to internet require this corporate proxy. What is the problem? Please help. A billion thanks in advance.

PS: Occasionally i encounter this error

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout 10000; Using SOCKS host, port: localhost, 1081;

Latest:

DEBUG: setDebug: JavaMail version 1.6.0 Dec 31, 2018 3:40:03 PM org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server run INFO: Starting proxy server at port 1081 Dec 31, 2018 3:40:03 PM org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server run INFO: waiting for new connection... DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle] DEBUG SMTP: need username and password for authentication DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=kwong, password= DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false Dec 31, 2018 3:40:03 PM org.simplejavamail.mailer.internal.socks.socks5server.SocksSession INFO: SESSION[1] opened from /127.0.0.1:36846 Dec 31, 2018 3:40:03 PM org.simplejavamail.mailer.internal.socks.socks5server.AnonymousSocks5Server run INFO: waiting for new connection... Dec 31, 2018 3:40:03 PM org.s implejavamail.mailer.internal.socks.AuthenticatingSocks5Bridge createSocketAuthenticated INFO: SESSION[1] bridging to remote proxy https://10.64.150.9:8080 , username: kwong@who.int, proxy bridge @ localhost:1081

检查您的代理服务器,我认为它期望的是HTTPS而不是HTTP,因此延迟了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM