Search in sources :

Example 1 with JavamailService

use of teammates.logic.core.JavamailService in project teammates by TEAMMATES.

the class EmailSenderTest method testConvertToMimeMessage.

@Test
public void testConvertToMimeMessage() throws Exception {
    EmailWrapper wrapper = getTypicalEmailWrapper();
    MimeMessage email = new JavamailService().parseToEmail(wrapper);
    assertEquals(new InternetAddress(wrapper.getSenderEmail(), wrapper.getSenderName()), email.getFrom()[0]);
    assertEquals(new InternetAddress(wrapper.getReplyTo()), email.getReplyTo()[0]);
    assertEquals(new InternetAddress(wrapper.getRecipient()), email.getRecipients(Message.RecipientType.TO)[0]);
    assertEquals(new InternetAddress(wrapper.getBcc()), email.getRecipients(Message.RecipientType.BCC)[0]);
    assertEquals(wrapper.getSubject(), email.getSubject());
    assertEquals(wrapper.getContent(), email.getContent().toString());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) JavamailService(teammates.logic.core.JavamailService) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 2 with JavamailService

use of teammates.logic.core.JavamailService in project teammates by TEAMMATES.

the class EmailSender method sendEmailCopyWithJavamail.

/**
 * Sends the given {@code message} with Javamail service regardless of configuration.
 */
private void sendEmailCopyWithJavamail(EmailWrapper message) throws EmailSendingException {
    // GAE Javamail is used when we need a service that is not prone to configuration failures
    // and/or third-party API failures. The trade-off is the very little quota of 100 emails per day.
    JavamailService javamailService = new JavamailService();
    // GAE Javamail requires the sender email address to be of this format
    message.setSenderEmail("admin@" + Config.getAppId() + ".appspotmail.com");
    message.setSubject("[Javamail Copy] " + message.getSubject());
    javamailService.sendEmail(message);
}
Also used : JavamailService(teammates.logic.core.JavamailService)

Aggregations

JavamailService (teammates.logic.core.JavamailService)2 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 Test (org.testng.annotations.Test)1 EmailWrapper (teammates.common.util.EmailWrapper)1