Sending the email to the following server failed : smtp.gmail.com:25
Asked Answered
M

5

16

When I try to send a mail from scala Playmework, I got following error,

[ERROR] [10/10/2013 13:31:16.263] [play-akka.actor.default-dispatcher-75] [TaskInvocation] Sending the email to the following server failed : smtp.gmail.com:25
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:25
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at com.typesafe.plugin.CommonsMailer.send(MailerPlugin.scala:241)
    at com.typesafe.plugin.MailerBuilder$class.sendHtml(MailerPlugin.scala:204)
    at com.typesafe.plugin.CommonsMailer.sendHtml(MailerPlugin.scala:215)
    at models.SignUpProcess$$anonfun$models$SignUpProcess$$sendEmail$1.apply$mcV$sp(SignUpProcess.scala:261)
    at akka.actor.DefaultScheduler$$anon$8.run(Scheduler.scala:193)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137)
    at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:319)
    at javax.mail.Service.connect(Service.java:169)
    at javax.mail.Service.connect(Service.java:118)
    at javax.mail.Transport.send0(Transport.java:188)
    at javax.mail.Transport.send(Transport.java:118)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    ... 12 more

How to solve this error?

SignUpProcess.scala

private def sendEmail(subject: String, recipient: String, bodyString:Html) {

        import scala.concurrent.duration._
        import play.api.libs.concurrent.Execution.Implicits._

        Akka.system.scheduler.scheduleOnce(1 seconds) {
          val mail = use[MailerPlugin].email
          mail.setSubject(subject)
          mail.addRecipient(recipient)
          mail.addFrom("[email protected]")
          println(bodyString)


          mail.sendHtml(bodyString.toString)
        }
}

application.conf

smtp.host = smtp.gmail.com
smtp.port = 465
smtp.ssl = true
smtp.tls = no
smtp.user = "[email protected]"
smtp.password = "mypassword"
Montpelier answered 10/10, 2013 at 10:6 Comment(1)
If you are getting this error despite trying every known solution, make sure you you don't have an antivirus running on your computer. After uninstalling Avast, everything worked smoothly.Dithyramb
R
21

1. Here is a working configuration for GMail :

smtp.host=smtp.gmail.com
smtp.port=587
smtp.ssl=yes
smtp.user="[email protected]"
smtp.password="myPassword"

You must use port 587 (and so activate SSL)

2. Also ensure that Two factor authentication is not activated (otherwise you must generate a new application password)

3. Another cause of connection fail : it can be seemed like a suspect connection.

So check mails received from google on your account to ensure the connection has not been blocked by google (happens if play is hosted in another country than the one you are used to connect manually)

Roundhouse answered 10/10, 2013 at 11:32 Comment(2)
No this also not works. Now my Play framework application run on my VPS(Virtual private server).Still I didn't have SSL certificate for my VPS.Shall I want to add SSL certificate to access the gmail SMTP with SSL? or need to configure anything in my VPS?Montpelier
@Ram There is a workaround to use smtp.gmail.com without SSL (link google group topic) But seems more complicated than add SSL on a server.Roundhouse
S
11

smtp:port=587 didn't work for me. but port 465 worked for me.

And turn on google less secure app settingenter image description here

smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
Stormie answered 3/9, 2015 at 10:57 Comment(1)
This was helpful.Legislative
S
7

You should first enable the access in Google for less secure App as shown in the above answer. Now Change the port to 465 and set ssl=true. Or you can set port=587 and tls=true. This is because port 465 is for SSL and port 587 is for TLS according to the official documentations.

port=465
ssl=true

**Note that port=587 with ssl=true won't work

Symbol answered 3/8, 2016 at 6:55 Comment(0)
R
0

If you feel all settings are correct, but still getting this message; I'd suggest to look at the attachments. I was sending a .JAR file which gmail servers won't allow you to attach and hence it was rejecting my email. I had to rename the file to .JARA to make it work.

Rhumb answered 20/11, 2016 at 23:51 Comment(0)
B
0

I've read all comment to here and I've had success. For this reason: this is my code that It could work perfectly.

smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
smtp.auth=true
smtp.user="[email protected]"
smtp.password=xxxxxxx
Bioscope answered 25/11, 2019 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.