I want to send an email in java.
I am using Simple Java Mail
my code:
final Email email = new Email();
email.setFromAddress("Name", "username@test.com");
email.setSubject("hey");
email.addRecipient("Name", "myemail@test.com", RecipientType.TO);
email.setText("Testing...");
new Mailer("smtpout.secureserver.net", 25, "username@test.com", "password").sendMail(email);
I always get the error
[MailException: Generic error: null]
which gets thrown by new Mailer
I have no idea what causes this excpetions and I hope you can clear things up.
Update 1:
Ok I get an AuthenticationFailedException
. That is strange.
The smtp server is correct , the port is correct, and username and password are also correct.
org.codemonkey.simplejavamail.MailException: Generic error: null
at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:249)
at controllers.SignUp.blank(SignUp.java:46)
at Routes$$anonfun$routes$1$$anonfun$apply$9$$anonfun$apply$10.apply(routes_routing.scala:156)
at Routes$$anonfun$routes$1$$anonfun$apply$9$$anonfun$apply$10.apply(routes_routing.scala:156)
at play.core.Router$HandlerInvoker$$anon$4$$anon$1.invocation(Router.scala:1086)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:33)
at play.GlobalSettings$1.call(GlobalSettings.java:57)
at actions.UserAction.call(UserAction.java:18)
at play.core.j.JavaAction$class.apply(JavaAction.scala:74)
at play.core.Router$HandlerInvoker$$anon$4$$anon$1.apply(Router.scala:1085)
at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126)
at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126)
at play.utils.Threads$.withContextClassLoader(Threads.scala:17)
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:125)
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115)
at akka.actor.Actor$class.apply(Actor.scala:318)
at play.core.ActionInvoker.apply(Invoker.scala:113)
at akka.actor.ActorCell.invoke(ActorCell.scala:626)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
at akka.dispatch.Mailbox.run(Mailbox.scala:179)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
at akka.jsr166y.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 org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:241)
... 24 more
This code runs fine on my machine(I get a ConnectException on the sendMail for the given parameters, but that is normal). Are you sure all the necessary dependencies are on your classpath? You need all the 5 jars at http://code.google.com/p/simple-java-mail/downloads/list on your classpath.