/** * Add a personalizaton to the email. * @param personalization a personalization. */ public void addPersonalization(Personalization personalization) { this.personalization = addToList(personalization, this.personalization); }
/** * Add a custom argument to the email. * @param key argument's key. * @param value the argument's value. */ public void addCustomArg(String key, String value) { this.customArgs = addToMap(key, value, this.customArgs); }
@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()); }
/** * Construct a new Mail object. * @param from the email's from address. * @param subject the email's subject line. * @param to the email's recipient. * @param content the email's content. */ public Mail(Email from, String subject, Email to, Content content) { this.setFrom(from); this.setSubject(subject); Personalization personalization = new Personalization(); personalization.addTo(to); this.addPersonalization(personalization); this.addContent(content); }
Mail mail = new Mail(); com.sendgrid.Email from = new com.sendgrid.Email(); from.setEmail(fromEmail); mail.setFrom(from); mail.addPersonalization(personalization); Content content = contentOfEmail(email); mail.addContent(content); request.setMethod(Method.POST); request.setEndpoint("mail/send"); request.setBody(mail.build()); Response response = sg.api(request); log.info("Status Code: {}", String.valueOf(response.getStatusCode()));
/** * Add a category to the email. * @param category the category. */ public void addCategory(String category) { this.categories = addToList(category, this.categories); }
/** * Add a header to the email. * @param key the header's key. * @param value the header's value. */ public void addHeader(String key, String value) { this.headers = addToMap(key, value, this.headers); }
/** * Add content to this email. * @param content content to add to this email. */ public void addContent(Content content) { Content newContent = new Content(); newContent.setType(content.getType()); newContent.setValue(content.getValue()); this.content = addToList(newContent, this.content); }
/** * Add a section to the email. * @param key the section's key. * @param value the section's value. */ public void addSection(String key, String value) { this.sections = addToMap(key, value, this.sections); }
/** * Add attachments to the email. * @param attachments attachments to add. */ public void addAttachments(Attachments attachments) { Attachments newAttachment = new Attachments(); newAttachment.setContent(attachments.getContent()); newAttachment.setType(attachments.getType()); newAttachment.setFilename(attachments.getFilename()); newAttachment.setDisposition(attachments.getDisposition()); newAttachment.setContentId(attachments.getContentId()); this.attachments = addToList(newAttachment, this.attachments); }