2016-01-18 39 views
2

我使用POST发送使用SendGrid的Web API的电子邮件。 HTML电子邮件正文具有与其相关的样式。将样式应用于SendGrid Web API中的html电子邮件

Screenshot of the email body

String body = 'api_user=username&api_key=pwd&to[][email protected]&subject=Message from SendGrid&html={text}&[email protected]'; 

    body = body.replace('{text}', emailBody); 
    HttpRequest req = new HttpRequest(); 
    req.setEndpoint('https://api.sendgrid.com/api/mail.send.json'); 
    req.setMethod('POST'); 
    req.setbody(body); 
    Http http = new Http(); 
    HTTPResponse response = http.send(req); 

收到电子邮件然而,当,它没有身体,没有。如果我从p和div中删除内联CSS,则呈现正文。如何保持HTML体中的样式不变?有没有其他方法?

回答

2

我的直觉是,这是关系到 '=' '风格=“'

尝试URL编码emailBody:

body = body.replace('{text}', encodeURIComponent(emailBody)); 
+2

你的预感是正确的过尽EncodingUtil.urlEncode(emailBody ,'UTF-8');以所需格式获取电子邮件。 – codeinprogress

相关问题