Created
January 16, 2018 11:51
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// step 1: create your mail | |
final Mail mail = new Mail(); | |
// step 2: add your credentials | |
final User user = new User(); | |
user.setEmail("[email protected]"); | |
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("[email protected]"); | |
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