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;
}
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());
}
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());
}
}
Aggregations