You need to sign in to do that
Don't have an account?

Unreadable email attachments sent via apex Messaging.sendEmail
Hi All,
We are sending record attachments via apex sendEmail email to salesforce users.
But one of our user is getting email attachment file in unreadable format.
I tried to open the same file by going to Salesforce record and can see the file is good and readable. Also tried to send these record attachments via developer console to myself and all the files are coming good.
Please advise
Thanks
Krishna
if it's one user have you checked if that user supports the mime type for that attachment? (for example if you send pdf to someone that doesn't have adobe installed it won't open - or associate with the correct application). What type of file is it, and have you ensured the user has the correct application to support that attachement?
Thanks for you quick response.
The file which we are sending via email attachment is a simple text file.
Thanks
Krishna
yes the file ext .txt is there.
One more thing actual file size in records notes and attachment is less than email attachment.
File in records notes and attachment is 766 bytes and same file sent as email attachment bacame more than 1 mb of unreadable content.
Code Snippet:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toaddresses);
mail.setTargetObjectId(userRec.Id);
mail.setWhatId(recordId);
mail.setTemplateId(templateId);
mail.setSaveAsActivity(false);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
List<Attachment> aList = [select Name, Body,BodyLength from Attachment where ParentId = :recordId];
for(Attachment a : aList){
System.debug('----a.name'+a.name+'----'+a.BodyLength);
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}
Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
mail.setFileAttachements(fileAttachments) is aready there, MIssed to add it into this thread.
I dont know if its resolved or not yet because it is hard to reproduce. We had only 2 occurences for this kind of issue.
I have raised case with Salesforce regarding this. Hoping i should get some resolution.
Thanks
Krishna