verifique em application.conf “mail.smtp = mock” este não comentado
criar classe que estende o
exemplo de classe Mailer :
package notifiers;
import java.io.StringWriter;
import org.apache.commons.mail.SimpleEmail;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import play.libs.Mail;
import play.mvc.*;
public class Mails extends Mailer {
public static void message(String target, String sender,
String subject, String targetname) {
try {
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put("senderName", targetname);
Template t = ve.getTemplate("app/views/Mails/email_template.vm");
StringWriter writer = new StringWriter();
t.merge(context, writer);
SimpleEmail email = new SimpleEmail();
email.setFrom(sender);
email.addTo(target);
email.setSubject(subject);
email.setMsg(writer.toString());
Mail.send(email);
} catch (Exception e) {
System.out.println("Error " + e.getMessage());
}
}
}
e depois crie o modelo de email. Exemplo de email_template.vm
DEAR $senderName,
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
bla bla bla lorem bla bla bla lorem bla bla bla lorem
Sincerely Yours
então em seu controlador coloque este código
public static void emailSender() {
Mails email = new Mails();
email.message("emailtarget@email.com", "emailsender@email.co.id",
"Test", "Yusuf Nugraha");
}
não se esqueça de configurar no arquivo de rotas também
“GET / email Application.emailSender”
Iam usando play framework 1.2.5, espero que seja útil 🙂