+ Start a Discussion

Trigger to send email with template

I have a trigger that is sent everytime a custom object record is created usind email services.   It works like an auto response so the person does not have to be a contact.  It currently works and brings in the merge field from the template but the graphics are not there and nothing show in outlook.

here is my code
trigger EmailNotify on Service_Call_Log__c (after insert) {
    for(service_call_log__C b: trigger.new){                           
                  EmailTemplate template = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'Case Created Service Call Log'];
//Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  //           mail.setTemplateId(template.id);
               String subject = template.Subject;
subject = subject.replace('{!Case.Account}', 'Your Case has been created');

String htmlBody = template.HtmlValue;
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Subject__c}', b.subject__C);
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Description__c}', b.Description__c);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 mail.setToAddresses(new String[] {b.web_email__C});
               mail.setSenderDisplayName('SFDC Developer');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Since you are saying it does not show any graphic content on outlook I assume that it is working fine on other email clients. If so, It is the issue with outlook where it blocks the graphics in email by default due to security reasons. You might have to look at this article that explains more on this http://office.microsoft.com/en-in/outlook-help/block-or-unblock-automatic-picture-downloads-in-e-mail-messages-HP001230040.aspx

If the issue is with all email clients, please review the below article and blog post which explains how you can send emails with images 

The template works when i use it in a work flow but when i use the trigger the images do not show in gmail or owa and in outlook nothing shows