Skip to content

Instantly share code, notes, and snippets.

@iggymacd
Created October 24, 2012 15:27
Show Gist options
  • Save iggymacd/3946743 to your computer and use it in GitHub Desktop.
Save iggymacd/3946743 to your computer and use it in GitHub Desktop.
import org.springframework.beans.BeanUtils;
import com.datacert.core.notifications.model.impl.EmailTemplate;
println entity.medLcrVersion.code
if(!"Initial - Draft".equalsIgnoreCase(entity.medLcrVersion.code) && !entityService.isNewInstance(entity)) {
println 'about to send email...'
def parent = queryService.query("Matter",queryService.and().add(queryService.property("medLcr.id").eq(entity.id))).first();
def customTemplateEngine = applicationContext.getBean("customTemplateEngine");
def configService = applicationContext.getBean("configurationService");
def emailService = applicationContext.getBean("emailService");
//def currentRequestProperties = applicationContext.getBean("currentRequestProperties");
//def currentUser = currentRequestProperties.get("currentUser")
// retrieve email template
def origEmailMessage = queryService.query("EmailTemplate",queryService.and().add(queryService.property("name").eq("Med LCR Notification Report"))).first();
def person = queryService.query("Person",queryService.and().add(queryService.property("user.ldapUser.username").eq(entity.updatedBy))).first();
def emailMessage = new EmailTemplate();
BeanUtils.copyProperties(origEmailMessage, emailMessage, ["id"] as String[]);
customTemplateEngine.evaluate(emailMessage, entity);
customTemplateEngine.evaluate(emailMessage, parent);
// retrieve "From address"
//def fromAddress = configService.getProperties().ClientAdministratorEmailAddress;
def fromAddress = "sysadmin@medtronicqa.e-invoice.com"
emailMessage.setFromAddress(fromAddress);
def toEmailAddress = "allan.macdonald@datacert.com"
//person.emailAddress;
emailMessage.setToAddress(toEmailAddress);
println 'about to send email...'
// send email
if (!emailService.sendMail(emailMessage)) {
System.out.println("Error while sending Matter LCR Notification Report !!!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment