function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gurpreet Singh SandhuGurpreet Singh Sandhu 

Trying to send attachments(all Formats) using Apex Email Service

Hello everyone,
USE CASE: When User finalize the Quote, sends an email along with Attachments(Quotes, POs, etc). I am using Visual Flow to get the Attachments and calling Apex Email Service.

WORKING: I am able to receive an email along with all the attachments, correct email template as expected. PDFs are coming along in the correct format.

ISSUE: All NON-PDFs attachments such as EXCEL, PNG, JPEGs are not showing in the correct format and infact, I am not able to open them from the Email.

Can someone please guide me to correct the issue? I beleive the issue is with:
q.setContentType('application/' + document.FileType);
Email Alert received through APEX Email Service


Compelete Code for setting the Email Atatchment:
Messaging.EmailFileAttachment q = new Messaging.EmailFileAttachment();
 q.setBody(document.VersionData);
q.setFileName(document.Title);
 q.setContentType('application/' + document.FileType);
attachments.add(q);
Thanks in Advance,
Guru Sandhu
 
Best Answer chosen by Gurpreet Singh Sandhu
David Zhu 🔥David Zhu 🔥
I would suggest do the followings:
1. update line 3 to:
q.setFileName(document.Title + '.' + document.FileExtension);   // make sure file FileExtension is included in your soql on ContentVersion.

2. Remove line 4.
q.setContentType('application/' + document.FileType);

All Answers

David Zhu 🔥David Zhu 🔥
I would suggest do the followings:
1. update line 3 to:
q.setFileName(document.Title + '.' + document.FileExtension);   // make sure file FileExtension is included in your soql on ContentVersion.

2. Remove line 4.
q.setContentType('application/' + document.FileType);
This was selected as the best answer
Gurpreet Singh SandhuGurpreet Singh Sandhu
Thank you David.

It worked. much appreciated.