Sending email in Java using Apache Commons email libs

前端 未结 3 1500
小鲜肉
小鲜肉 2021-01-30 18:48

I am using Apache Commons Email library to send emails, but I am not able to send them via GMail SMTP server.
Can anyone provide sample code which works with GMail SMTP serv

3条回答
  •  醉梦人生
    2021-01-30 19:25

    Sending emails to the GMail SMTP server requires authentication and SSL. The username and password is pretty straight forward. Make sure you have the following properties set to enable authentication and SSL and it should work.

    mail.smtp.auth=true
    mail.smtp.starttls.enable=true
    

    To the sample code add the following to enabled TLS.

    For API-Versions < 1.3 use:
    email.setTSL(true);
    the method is deprecated for versions >= 1.3, and instead you should use: email.setStartTLSEnabled(true);

提交回复
热议问题