You need to sign in to do that
Don't have an account?
MIME Settings for ICS as multipart/alternative
I am building an email with Messaging.SingleEmailMessage. The email should include TXT, HTML, and ICS versions and be received by an Outlook recipient as a calendar invite (not as an email with an attachment). The key is in setting the ICS attachment as an option in the same "content-type: multipart/alternative" section as the TXT and HTML versions. However, when I build the email with setPlainTextBody, setHtmlBody, and setFileAttachments, it sets the ICS attachment in its own "content-type" section.
How can I write my code to bring the .ICS file into the "Content-type: multipart/alternative" block with the TXT & HTML?
My current code:
How can I write my code to bring the .ICS file into the "Content-type: multipart/alternative" block with the TXT & HTML?
My current code:
public static void sendEventInviteICS(String bodyTXT, String bodyHTML, String subject, String fromAddress, String displayName, List<String> toAddress, List<String> ccAddress){ //Create Message Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage(); msg.setReplyTo(fromAddress); msg.setSenderDisplayName(displayName); msg.setToAddresses(toAddress); msg.setCcAddresses(ccAddress); msg.setSubject(subject); //Create TXT Version msg.setPlainTextBody(bodyTXT); //Create HTML Version msg.setHTMLBody(bodyHTML); //Create ICS Attachment Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName('Meeting Invite.ics'); efa.setContentType('text/calendar'); Blob b = buildICSAttachment(); efa.setBody(b); msg.setFileAttachments(new Messaging.EmailFileAttachment[]{efa}); //Send the Email Messaging.sendEmail(new Messaging.SingleEmailMessage[]{msg}); }MIME result from current code:
Date: Tue, 9 Dec 2014 21:16:26 +0000 From: Isaac Lewis <ilewis@afs.net> Reply-To: <djillumine@gmail.com> To: "ilewis@afs.net" <ilewis@afs.net> Subject: Sandbox: This is the subject MIME-Version: 1.0 Content-type: multipart/mixed; boundary="B_3500983009_1157947" > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3500983009_1157947 Content-type: multipart/alternative; boundary="B_3500983009_1123381" --B_3500983009_1123381 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit This is the text body --B_3500983009_1123381 Content-type: text/html; charset="US-ASCII" Content-transfer-encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"> </head> <body> <i>This is the html body</i> </body> </html> --B_3500983009_1123381-- --B_3500983009_1157947 Content-type: text/calendar; name="Attachment Name.ics" Content-disposition: attachment; filename="Attachment Name.ics" Content-transfer-encoding: base64 QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVRVUVTVA0KUFJPRElEOk1pY3Jvc29mdCBFeGNo= --B_3500983009_1157947--Desired MIME Result (boundaries around ICS have been moved to be part of the "Content-type: multipart/alternative" block):
Date: Tue, 9 Dec 2014 21:16:26 +0000 From: Isaac Lewis <ilewis@afs.net> Reply-To: <djillumine@gmail.com> To: "ilewis@afs.net" <ilewis@afs.net> Subject: Sandbox: This is the subject MIME-Version: 1.0 Content-type: multipart/mixed; boundary="B_3500983009_1157947" > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3500983009_1157947 Content-type: multipart/alternative; boundary="B_3500983009_1123381" --B_3500983009_1123381 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit This is the text body --B_3500983009_1123381 Content-type: text/html; charset="US-ASCII" Content-transfer-encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"> </head> <body> <i>This is the html body</i> </body> </html> --B_3500983009_1123381 Content-type: text/calendar; name="Attachment Name.ics" Content-disposition: attachment; filename="Attachment Name.ics" Content-transfer-encoding: base64 QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVRVUVTVA0KUFJPRElEOk1pY3Jvc29mdCBFeGNo= --B_3500983009_1123381-- --B_3500983009_1157947--
https://developer.salesforce.com/forums/ForumsMain?id=906F000000093eNIAQ
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008pwTIAQ
http://salesforce.stackexchange.com/questions/28417/creating-custom-mime-contents-in-emails
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008x9cIAA
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yOnIAI
efa.setContentType('text/calendar'); to efa.setContentType('text/calendar; charset=utf-8; method=REQUEST');
Please refer below link with similar issue:
https://developer.salesforce.com/forums/?id=906F0000000BP8TIAW
Hope this works for you.