nicholas
nicholas

Reputation: 2772

Apache Common Mails: Exception: Sending the email to the following server failed : smtp.gmail.com:587

I implement automatic email sender after selenium execution and it works for non proxy environment but it does not work at corporate proxy environment. Anyone know what wrong with it? What need to change?

Code:

// Create the email message
            MultiPartEmail email = new MultiPartEmail();
            email.setHostName("smtp.gmail.com");
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator("[email protected]", "giqqpudmcjjmpbcc"));
            email.setFrom("[email protected]", "Nicholas Wong");
            email.addTo("[email protected]", "Nicholas Wong");
            email.addTo("[email protected]", "Nicholas Gann");
            email.setBounceAddress("[email protected]");
            email.setSubject("ePQS Automation Testing Report");
            email.setMsg("Please find the ePQS Automation Testing Report from attachment");
            email.setStartTLSEnabled(true);
            email.setSSLCheckServerIdentity(true);  
            email.setDebug(true); 

            email.getMailSession().getProperties().setProperty("mail.smtp.auth", "true");
            email.getMailSession().getProperties().setProperty("mail.smtp.starttls.enable", "true");
            email.getMailSession().getProperties().setProperty("mail.smtp.port", "587");
            email.getMailSession().getProperties().setProperty("mail.https.proxy.host", "http://10.64.150.9");
            email.getMailSession().getProperties().setProperty("mail.https.proxy.port", "8080");

Our company proxy require authentication. I believe javax.mail does not support it. Any java mail that support proxy authentication? Apache James.

How to set the proxy properly? Any idea? A billion thanks for your help.

Error:

DEBUG: JavaMail version 1.6.2 DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map 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 587, isSSL false [INFO ] 2019-01-10 09:45:18.237 [main] - Exception: Sending the email to the following server failed : smtp.gmail.com:587

Upvotes: 1

Views: 1260

Answers (1)

Bill Shannon
Bill Shannon

Reputation: 29971

In your property setting, you have to change "protocol" to the actual name of the protocol you're using, e.g., "smtp".

Upvotes: 1

Related Questions