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
Abhishek Kumar 407Abhishek Kumar 407 

I have a requirement to send multiple attachment(in their original format) with a click of "Send" button to my email Id:-

For your reference I am posting Apex and VF code by which I can select only one attachement of .zip format. Kindly help.
(Kindly mark what code you are adding or removing with proper comments. As I am new to Salesforce, So it'd be easy to understand. Thanks in advance)

//Apex Code
public class emailWithAttach
{
    public String subject          {set;get;}
    public String body             {set;get;}
   
    public blob attach             {set;get;}
    public List<Contact> contacts  {set;get;}
      
    public emailWithAttach()
    {
        contacts=[Select Id, LastName, Email from Contact  where Email='abhishekk.twopirconsulting@gmail.com'];
    }
    public PageReference Send()
    {
         List<String> mails=new List<String>();
        For(Contact c:contacts)
        {
            mails.add(c.Email);
        }
        messaging.SingleEmailMessage msg1=new messaging.SingleEmailMessage();
        msg1.setSubject(subject);
        msg1.setPlainTextBody(body);
        msg1.setToAddresses(mails);
        Messaging.Email[] emails=new Messaging.Email[]{msg1};
        
        List<Messaging.EmailFileAttachment> fileAttachments=new List<Messaging.EmailFileAttachment>();
        Messaging.EmailFileAttachment efa=new messaging.EmailFileAttachment();
        efa.setFileName('Test.zip');
        efa.setBody(attach);
        fileAttachments.add(efa);
     
        msg1.setFileAttachments(fileAttachments);
        Messaging.sendEmail(emails);
        PageReference p=new PageReference('https://mail.google.com/mail/u/0/#inbox');
        p.setRedirect(true);
        return p;
    }

}
//VF Code
<apex:page controller="emailWithAttach">
    <apex:form >
        <apex:pageBlock title="Email with multiple Attachement">
            <apex:pageBlockButtons location="Bottom">
            	<apex:commandButton value="Send" action="{!Send}"/>
            </apex:pageBlockButtons>
           
            Subject:<br/><apex:inputText value="{!subject}" size="60"/><br/><br/>
            Attachement for Zip file only:<br/><apex:inputFile value="{!attach}" /><br/><br/>
            Body:<br/><apex:inputTextarea value="{!body}"  cols="60" rows="20"/>
           
        </apex:pageBlock>
    </apex:form>
</apex:page>