I am trying to use Play Framework to send out email. In applications.conf, when I set smtp.mock=true , it works perfectly well:
[info] application - HTML: Welcome to Play20StartApp. <br> Click on this link : http://localhost:9000/confirm/d77ea256-0d2e-4df5-b66e-e034159f8042 to confirm your email.<br><br>--<br>null
[debug] application - Mail sent - SMTP:smtp.google.com:465 SSL:yes user:[email protected] password:password
However, when I comment smtp.mock=true and attempt to send real emails, I get this error:
[debug] application - Mail.sendMail: Mail will be sent to [email protected]
[ERROR] [09/26/2013 03:46:05.014] [application-akka.actor.default-dispatcher-2] [TaskInvocation] From address required
org.apache.commons.mail.EmailException: From address required
I have set smtp.user to a proper value, i.e. [email protected] . Any idea what causes this error?
Troubleshooting steps
- The emails used are real emails, for the purpose of posting, they are anonymized. Likewise, a real domain name is used
- Tested with a working local mail server (exim), as well as directly sending through Gmail (smtp.google.com) and Google Apps (aspmx.l.google.com) servers. These settings have been verified using mail clients.
The Java code snippet below works perfectly,
import java.util.; import javax.mail.; import javax.mail.internet.; import javax.activation.;
public class SendEmail { public static void main(String [] args) { String to = "[email protected]"; String from = "[email protected]"; String host = "localhost"; Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); // Get the default Session object. Session session = Session.getDefaultInstance(properties); try{ MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Subject of email"); message.setText("This is actual message"); Transport.send(message); System.out.println("Sent message successfully...."); }catch (MessagingException mex) { mex.printStackTrace(); } } }