public static void main(String[] args) throws SendGridException { SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY); SendGrid.Email email = new SendGrid.Email(); email.addTo(TO_EMAIL); email.setFrom(SENDGRID_SENDER); email.setSubject("This is a test email"); email.setText("Example text body."); SendGrid.Response response = sendgrid.send(email); if (response.getCode() != 200) { System.out.print(String.format("An error occured: %s", response.getMessage())); return; } System.out.print("Email sent."); }
@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()); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((bccSettings == null) ? 0 : bccSettings.hashCode()); result = prime * result + ((bypassListManagement == null) ? 0 : bypassListManagement.hashCode()); result = prime * result + ((footerSetting == null) ? 0 : footerSetting.hashCode()); result = prime * result + ((sandBoxMode == null) ? 0 : sandBoxMode.hashCode()); result = prime * result + ((spamCheckSetting == null) ? 0 : spamCheckSetting.hashCode()); return result; }
/** * 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); }
/** * Place the object into an empty state. */ public void reset() { this.clearMethod(); this.clearBaseUri(); this.clearEndpoint(); this.clearBody(); this.clearHeaders(); this.clearQueryParams(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((clickTrackingSetting == null) ? 0 : clickTrackingSetting.hashCode()); result = prime * result + ((googleAnalyticsSetting == null) ? 0 : googleAnalyticsSetting.hashCode()); result = prime * result + ((openTrackingSetting == null) ? 0 : openTrackingSetting.hashCode()); result = prime * result + ((subscriptionTrackingSetting == null) ? 0 : subscriptionTrackingSetting.hashCode()); return result; }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys */ public SendGrid(String apiKey) { this.client = new Client(); initializeSendGrid(apiKey); }
/** * 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); }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param client the Client to use (allows to customize its configuration) */ public SendGrid(String apiKey, Client client) { this.client = client; initializeSendGrid(apiKey); }
/** * Makes the call to the SendGrid API, override this method for testing. * @param request the request to make. * @return the response object. * @throws IOException in case of a network error. */ public Response makeCall(Request request) throws IOException { return client.api(request); }
/** * Add a personalizaton to the email. * @param personalization a personalization. */ public void addPersonalization(Personalization personalization) { this.personalization = addToList(personalization, this.personalization); }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param test is true if you are unit testing */ public SendGrid(String apiKey, Boolean test) { this.client = new Client(test); initializeSendGrid(apiKey); }
/** * 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); }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param client the Client to use (allows to customize its configuration) */ public SendGrid(String apiKey, Client client) { this.client = client; initializeSendGrid(apiKey); }
/** * Makes the call to the SendGrid API, override this method for testing. * @param request the request to make. * @return the response object. * @throws IOException in case of a network error. */ public Response makeCall(Request request) throws IOException { return client.api(request); }
/** * Add a category to the email. * @param category the category. */ public void addCategory(String category) { this.categories = addToList(category, this.categories); }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys * @param test is true if you are unit testing */ public SendGrid(String apiKey, Boolean test) { this.client = new Client(test); initializeSendGrid(apiKey); }
/** * 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); }
/** * Construct a new SendGrid API wrapper. * @param apiKey is your SendGrid API Key: https://app.sendgrid.com/settings/api_keys */ public SendGrid(String apiKey) { this.client = new Client(); initializeSendGrid(apiKey); }