EmailException: Sending the email to the following

2020-04-15 20:24发布

问题:

I wrote a program to send mail from my gmail account using scala Play 2.3.8 then i got the following exception:

[EmailException: Sending the email to the following server failed : smtp.gmail.com:465] at MailerPlugin.send(email)

my code is as follows:

  val email = Email(
  "A personal mail",
  "LeeSa <xxxxxx@gmail.com>",
  Seq("Recepient <yyyyyy@gmail.com>"),
  // adds attachment
  attachments = Seq(

  ),
  bodyHtml = Some("""
  <html>
    <body>
    <h3>Hai ,</h3>
    <p> This is a test message. </p>
    </body>
  </html>
  """)
)
MailerPlugin.send(email)

application.conf contains the configuration

    smtp.host=smtp.gmail.com
    smtp.port=465
    smtp.ssl=yes
    smtp.tls=yes
    smtp.user="xxxxxxx@gmail.com"
    smtp.password="MyPassword"

Anyone can help me?

回答1:

This kind of exception commonly occurs because the service provider protects your account by modern security standards.

You have to disable this for executing your application in the right way. You can do this by visiting the link https://www.google.com/settings/security/lesssecureapps
after log in into your Gmail account, and turn on the access for the less secure app.

I hope this will bring you out of the issue. :-)