Skip to main content
I am using apex:inputfile to get the file uploaded and want to attach it email attachment and send it as email.. I tried

 

public Transient Attachment emailAttachment{get;set;}

<apex:inputFile value="{!emailAttachment.body}" filename="{!emailAttachment.name}" id="file"/>

List<Messaging.Emailfileattachment> fileList = new List<Messaging.Emailfileattachment>();

if(emailAttachment != null)

{

Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();

efa1.setBody(emailAttachment.Body);

efa1.setFileName(emailAttachment.name);

fileList.add(efa1);

}

for(String toContactId : toAddressesList) {

List<Messaging.SingleEmailMessage> msgList = new List<Messaging.SingleEmailMessage>();

Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();

msg.setTargetObjectId(toContactId);

msg.setFileAttachments(fileList);

msg.setHTMLBody(htmlEmailBody);

msg.setSubject(EmailSubject);

msgList.add(msg);

}

Messaging.sendEmail(msgList);

But I can't able to get the file in the email attachment. Any ideas on how to do it?
3 Antworten
  1. 30. Okt. 2015, 11:10
    @ulas Yes... after sending email only, the task is saved and added as attachment. Is it possible to get the body from input file itself?