Trying to get Play! Framework to send an email with an attachment. Code below works fine if I don't add the attachment to the message. I've tried both with Play's Mailer class and with the Apache Commons classes (as below), but in both cases, the page just sits there with a spinner (Chrome) and no email is received.
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL(base + "public/images/triangles.png"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("test");
attachment.setName("test");
emailaddress = "[email protected]";
MultiPartEmail email = new MultiPartEmail();
email.setDebug(true);
email.addTo(emailaddress);
email.setFrom("Testing <[email protected]>");
email.setSubject("Testing email");
try
{
email.attach(attachment);
}
catch (EmailException ex)
{
System.out.println(ex.getMessage());
}
email.setMsg("test email");
email.send();
Im guessing you've already had a look at the Examples for Apache Commons and Sending e-mail - Play! Framework 1.1?
IMO I'd suggest using a well known library with loads of documentation and examples like JavaMail and their api.
Here are a few tutorials that will get you started immediately:
An example of using the JavaMail to send a Email with attachment via gmail is:
}
HTH
References: