Skip to content

Instantly share code, notes, and snippets.

@michaelneu
Created January 16, 2018 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelneu/19ad1cee3e3275d65ee0c3c93a4898d3 to your computer and use it in GitHub Desktop.
Save michaelneu/19ad1cee3e3275d65ee0c3c93a4898d3 to your computer and use it in GitHub Desktop.
An example integration for OTH Regensburg's software development course (see https://github.com/michaelneu/gorillamail)
// step 1: create your mail
final Mail mail = new Mail();
// step 2: add your credentials
final User user = new User();
user.setEmail("barb@gorillamail.space");
user.setPassword("p4ssword!");
// step 3: set your template
final Template template = new Template();
template.setId(42); // copy this id from your dashboard
mail.setTemplate(template);
// step 4: set your mail's receipient
final Header toHeader = new Header();
toHeader.setName("to");
toHeader.setValue("acidburn@contoso.com");
mail.getHeaders().add(toHeader);
/// step 5: set your mail's subject
final Header subjectHeader = new Header();
subjectHeader.setName("subject");
subjectHeader.setValue("Your weekly sports update");
mail.getHeaders().add(subjectHeader);
// step 6: if you used variables in your template (like
// "Hi {{firstName}}"), you can define them here
final Variable var = new Variable();
var.setName("firstName");
var.setValue("Bob");
mail.getVariables().add(var);
// optional: if you don't want to pay for your mail,
// allow gorillamail to insert an ad
mail.setAd(true);
// hit send
try {
mailService.sendMail(user, mail);
} catch (MailException_Exception exception) {
// handle exception (in case something went wrong on our side)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment