0

http://www.modelmetrics.com/technology-viewpoint/cloud-to-cloud-using-aws-simple-email-service-from-force-com/

I am using above blog content and this is excellent article on how to send emails through amazon.I tried with html content and was successful.

While if i try using tag in html body i send images are not rendering proper in email.Is it something i am missing here.

 public PageReference constructor(){
    try{

        AWSKeys awsKey = AWSKeys.getInstance(AWSCredentialName);
        SES sesEmail = new SES(awsKey.key,awsKey.secret);

        List<String> recipients = new List<String>();
        recipients.add('[email protected]'); 
        String sender = '[email protected]';
        String subject = 'Test message';
        Campaign c=[Select c.Id,c.Name,c.Email_Template__r.Template_HTML__c, c.Email_Template__r.Email_Template_Name__c, c.Email_Template__c From Campaign c where id='701i0000000Mk35'];
        String body =(c.Email_Template__r.Template_HTML__c).unescapeHtml4();
        body=body.replace('{!Campaign.Name}', c.Name);
        body=body.replace('{!Campaign.ID}',c.Id);

        sesEmail.sendEmail(recipients,sender,subject,body);

    }catch(AWSKeys.AWSKeysException AWSEx){

         ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.FATAL, AWSEx.getMessage());
         ApexPages.addMessage(errorMsg);

    }

Presently i have hardcoded Campaign ID just for testing and html body is in rich text field i have created in my org.Is there a way to render images on browser and send using tag in html content ?

3 Answers 3

1

Images in rich text field need authenticated access (or access via sites etc), an easy approach would be to store your images in the document object and set them to be publicly available.

1
  • Thanks for your reply.I will try your recommendation.Thanks! Commented Apr 22, 2013 at 19:05
1

Amazon MWS API requires all the API calls to be signed requests. Currently they are using Signature Version 4 for signing the requests. For Amazon SES API to call perfectly you need to check the API's Code that I have checked from amazonmwsapi web service.

0
 /**
 * Encode the email as described in the SES documentation:
 * http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/
 **/ 
private String encodeEmail()
{
    String email = 'Action=SendEmail';
    email += '&Source='+EncodingUtil.urlEncode(this.fromAddress,'UTF-8');
    for(Integer i=1;i<this.toAddresses.size()+1;i++)
    {
        email += '&Destination.ToAddresses.member.'+i+'='+EncodingUtil.urlEncode(this.toAddresses[i-1],'UTF-8');
    } 
    email += '&Message.Subject.Data='+EncodingUtil.urlEncode(this.subject,'UTF-8');
    email += '&Message.Body.Html.Data='+EncodingUtil.urlEncode(this.body,'UTF-8');
    return email;
}

I have modified some code to support html and also now in my rich text field i use the following code

<h1> how is it going?</h1><img src="https://s3.amazonaws.com/Traffic_Email_Templates/Appetizer/2_3col.jpg" width="180" height="180" />

And its pulling perfectly.

Here is how i make use of one of recent String methods

 String body =(c.Email_Template__r.Template_HTML__c).unescapeHtml4();

This unescapes html4 for me .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .