Search in sources :

Example 6 with Mail

use of com.sendgrid.Mail in project CollectiveOneWebapp by CollectiveOne.

the class EmailService method prepareActivitySendNowEmail.

private Mail prepareActivitySendNowEmail(List<Notification> notifications) {
    Mail mail = new Mail();
    Email fromEmail = new Email();
    fromEmail.setName(env.getProperty("collectiveone.webapp.from-mail-name"));
    fromEmail.setEmail(env.getProperty("collectiveone.webapp.from-mail"));
    mail.setFrom(fromEmail);
    mail.setSubject("Activity in CollectiveOne");
    for (Notification notification : notifications) {
        if (notification.getSubscriber().getUser().getEmailNotificationsEnabled()) {
            Personalization personalization = basicInitiativePersonalization(notification);
            String message = getActivityMessage(notification);
            personalization.addSubstitution("$MESSAGE$", message);
            mail.addPersonalization(personalization);
        }
        notification.setEmailState(NotificationEmailState.DELIVERED);
        notificationRepository.save(notification);
    }
    mail.setTemplateId(env.getProperty("collectiveone.webapp.initiative-activity-template"));
    return mail;
}
Also used : Mail(com.sendgrid.Mail) Email(com.sendgrid.Email) Personalization(com.sendgrid.Personalization)

Example 7 with Mail

use of com.sendgrid.Mail in project teammates by TEAMMATES.

the class EmailSenderTest method testConvertToSendgrid.

@Test
public void testConvertToSendgrid() {
    EmailWrapper wrapper = getTypicalEmailWrapper();
    Mail email = new SendgridService().parseToEmail(wrapper);
    assertEquals(wrapper.getSenderEmail(), email.getFrom().getEmail());
    assertEquals(wrapper.getSenderName(), email.getFrom().getName());
    assertEquals(wrapper.getRecipient(), email.personalization.get(0).getTos().get(0).getEmail());
    assertEquals(wrapper.getBcc(), email.personalization.get(0).getBccs().get(0).getEmail());
    assertEquals(wrapper.getReplyTo(), email.getReplyto().getEmail());
    assertEquals(wrapper.getSubject(), email.getSubject());
    assertEquals("text/plain", email.getContent().get(0).getType());
    assertEquals(Jsoup.parse(wrapper.getContent()).text(), email.getContent().get(0).getValue());
    assertEquals("text/html", email.getContent().get(1).getType());
    assertEquals(wrapper.getContent(), email.getContent().get(1).getValue());
}
Also used : Mail(com.sendgrid.Mail) SendgridService(teammates.logic.core.SendgridService) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 8 with Mail

use of com.sendgrid.Mail in project teammates by TEAMMATES.

the class SendgridService method sendEmailWithService.

@Override
protected void sendEmailWithService(EmailWrapper wrapper) throws IOException {
    Mail email = parseToEmail(wrapper);
    SendGrid sendgrid = new SendGrid(Config.SENDGRID_APIKEY);
    Request request = new Request();
    request.setMethod(Method.POST);
    request.setEndpoint("mail/send");
    request.setBody(email.build());
    Response response = sendgrid.api(request);
    if (isNotSuccessStatus(response.getStatusCode())) {
        log.severe("Email failed to send: " + response.getBody());
    }
}
Also used : Response(com.sendgrid.Response) SendGrid(com.sendgrid.SendGrid) Mail(com.sendgrid.Mail) Request(com.sendgrid.Request)

Aggregations

Mail (com.sendgrid.Mail)8 Email (com.sendgrid.Email)4 Personalization (com.sendgrid.Personalization)4 Request (com.sendgrid.Request)4 Response (com.sendgrid.Response)4 IOException (java.io.IOException)3 Content (com.sendgrid.Content)1 SendGrid (com.sendgrid.SendGrid)1 Initiative (org.collectiveone.modules.initiatives.Initiative)1 Test (org.testng.annotations.Test)1 EmailWrapper (teammates.common.util.EmailWrapper)1 SendgridService (teammates.logic.core.SendgridService)1