Skip to content

Instantly share code, notes, and snippets.

@robertacosta
Last active August 29, 2015 14:19
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 robertacosta/8f98ba70f16afaf97bdc to your computer and use it in GitHub Desktop.
Save robertacosta/8f98ba70f16afaf97bdc to your computer and use it in GitHub Desktop.
Developer Example of sending an email with SendGrid ASM
private void sendPatientAssignment(Principle user, String patientName, String patientRoom) {
Logger logger = LoggerFactory.getLogger(AdminController.class);
SendGrid sendgrid = new SendGrid(System.getenv("SENDGRID_API_KEY"));
SendGrid.Email email = new SendGrid.Email();
email.addTo(user.getEmail());
email.setFrom(System.getenv("SENDGRID_FROM_EMAIL"));
email.setSubject("Attemper EMR. You have a new patient assignment.");
email.setHtml(user.getFirstName());
email.setASMGroupId(124);
email.getSMTPAPI().addFilter("templates", "enable", 1);
email.getSMTPAPI().addFilter("templates", "template_id", "e95d8718-383c-4741-9ebe-34d083b1cc10");
email.getSMTPAPI().addSubstitution("-name-", patientName);
email.getSMTPAPI().addSubstitution("-room-", patientRoom);
try {
sendgrid.send(email);
} catch (SendGridException e) {
logger.error("Failed to email user patient assignment: " + e.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment