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
Manoj ThangavelManoj Thangavel 

Attaching files in Apex Emails

Apex emails with email attachments not supporting content version file types directly in lightning.

We need alternative option for email attachment type with Contentversion filetypes.
or some i heard mime type.

i am not sure, but nothing works for me now, simply am ignoring the Email attachment content type and appending the fiel name with content version file type as extemsion.
This could be temprory fixbut need a fix.
Raj VakatiRaj Vakati
You can do it like below 

 
List<id> ContentDocumentids = new List<id>();

for(contentDocumentLink CDLink : [SELECT LinkedEntityid, ContentDocumentid FROM contentDocumentLink WHERE LinkedEntityid=:<b>'Object id'</b>])
			{
			   ContentDocumentids.add(CDLink.ContentDocumentid);  
			}
			for ( ContentVersion cversion : [SELECT title, 
													PathOnClient, FileType,
													versiondata 
											  FROM contentversion 
											  WHERE ContentDocumentId IN :ContentDocumentids  
											   AND title LIKE 'WOCF%'])
			 {
			  blob WOCFbody = cversion.versiondata;
			  system.debug('body : '+WOCFbody+'-----------'+cversion.title);
			  Messaging.Emailfileattachment efa1 = new Messaging.Emailfileattachment();
			  efa.setFileName(war2.opportunity__r.name+'-'+cversion.title+'.'cversion.FileType);
			  efa.setBody(WOCFbody);
			  fileAttachments.add(efa); 
			 }

https://developer.salesforce.com/forums/?id=9060G0000005VtDQAU
https://help.salesforce.com/articleView?id=case_interaction_attaching_files_to_email.htm&type=5

https://salesforce.stackexchange.com/questions/156456/files-as-email-attachment-from-apex

 
Manoj ThangavelManoj Thangavel
Thanks Venkat. Finally I have done the same as you did like filename appended with file type. But for some filetypes It behaves wired, ex for text files ext should be .txt, but our code append like .TEXT We need to find another way. Thanks, Manoj T