Unable to send email via google smtp on centos VPS
I am trying to send email via google SMTP.
The code is working fine in my local windows PC in tomcat. But i got this
error on my centos VPS
org.apache.commons.mail.EmailException: Sending the email to the following
server failed : smtp.googlemail.com:465
Here is code, please check it -
// Create the email message
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.addTo(e_mail, f_name+" "+l_name);
email.setFrom("me@gmail.com", "something.com - Account activation");
email.setSubject("something.com - Account activation email");
// embed the image and get the content id
URL url = new URL("http://something.com/out.php/i6964_logo-email.gif");
String cid = email.embed(url, "BizzKiss logo");
// set the html message
email.setHtmlMsg("<html><body>Something</body></html>");
// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
email.setTLS(true);
// send the email
email.send();
out.println("Email sent to "+e_mail+"<br/>Please check your email for
activation message.Not found? Please check your spam folder.");
No comments:
Post a Comment