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
Vetriselvan ManoharanVetriselvan Manoharan 

Email attachment visualforce

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?
AshlekhAshlekh
Hi,

Please find the below link and may be you will get your ans

http://stackoverflow.com/questions/18848444/salesforce-email-attachemnt

https://developer.salesforce.com/forums/?id=906F000000097SRIAY

-Thanks
Ashlekh Gera
Ulas KutukUlas Kutuk
@Vetriselvan look like you did not insert the attachments in to SF
Vetriselvan ManoharanVetriselvan Manoharan
@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?