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
SMasterSMaster 

Is there any way to send an Email with Attachment??

Hi All,

 

I want to send an email with the selected Attachment from Notes and Attachment related list....

 

i.e. i have some file inside Notes and Attachment related list.. and i want to select one file out of them.. and want to email that with some template.. please let me kow how can i do that...

 

 

Thanks

b-Forceb-Force

I think you need to move with custom Visual force page approach,

 

And need to implement custom functionality to pick Email template and Attachements, As by using Salesforce Standard

salesforce.com/_ui/core/email/author/EmailAuthor functionality  will allow you to pick attachment only from documents,

 

Not from related list attachments.


Please redefine your requirement in more detail way, so I can suggest accordingly


Cheers,

Bala

SMasterSMaster

Hi Bala,

 

My requirement is as follows:

 

I need a button on the Custom Object Page layout, to send an email in a specified Template with an Attachment. Before sending the mail I need to select one attachment from all attachments that are available inside Notes and Attachment Related list.

 

Now, in order to achieve this

(1) i have create a Checkbox on the page

(2) Onclick of a detail page button.. i am running the javascript code to make the checkbox as true i.e. checked

(3) Create a workflow, when the checkbox is True i.e. checked and email alert will fire with the selected Email Template.

 

Now, i am able to send an email with a template but.. i am not able to understand how can i select and relate attachment with it.

 

Or,

i will have to follow another approach to fulfill the needs...

 

Please let me know the way of achieving it...

 

 

SMasterSMaster

 

Also, please get the following details:

 

Custom Object Name is:   opportunity_proposals__c

Custom field that contain the email id:  SMEs_Email__c

 

 

Javascript code i have written to update the checkbox value:

 

{!requireScript("/soap/ajax/20.0/connection.js")}
{!requireScript("/soap/ajax/20.0/apex.js")}

var temp= new sforce.SObject("opportunity_proposals__c");
temp.Id ="{!opportunity_proposals__c.Id}";
temp.EMAIL_TO_SME__c = 'True';
try
{
sforce.connection.update([temp]);
}
catch(e)
{
alert(e)
}

 

after that a simple workflow with Email alert action...  :)

 

this is all what i have...

b-Forceb-Force

Hey,

If you want to select attachment from related list of notes and attachment , you need to go for Visualforce page ,

Query related attachment and attach to email.

** here we can not use standard sendEmail page , there we can select attachment only from documents 

 

Hope It will help you.

 

Cheers,

Bala

SMasterSMaster

Hi Bala,

 

Based on your suggestion... i have tried creating the visualforce page and an apex class... But how can i select one attachment from the visualforce page and send it as an attachment inside mail??? is getting difficult

 

The Apex class is:

 

public class testmail
{
 ApexPages.StandardController controller;   
 
 public opportunity_proposals__c q
 {
 get;set;
 }
    
 String op = ApexPages.currentPage().getParameters().get('id');
 
 public Id oppr   
 {    get;set;    }       
 
 public testmail(ApexPages.StandardController ctrl)   
 {      
 oppr = ctrl.getRecord().Id;        
 }
 
 public PageReference emailAtt()
 {
 
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{'SMaster@gmail.com'};
        mail.setToAddresses(toAddresses);
        mail.setReplyTo('SMaster@gmail.com');
        mail.setSenderDisplayName('CRM Support');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setTargetObjectId('005Q0000000FR7f');
        mail.setTemplateId('00XQ0000000QULj');
        mail.saveAsActivity = false;    
        
      //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
        {
     // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        fileAttachments.add(efa);
        }
        mail.setFileAttachments(fileAttachments);

      //Send email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        return null;
}
}

 

 

and the Visualforce page is:

 

 

<apex:page standardController="opportunity_proposals__c" extensions="testmail">
  <apex:form >
   <apex:pageBlock title="Attachments">
   <apex:pageBlockButtons >
            <apex:commandButton value="Send" action="{!emailAtt}"/>
        </apex:pageBlockButtons>


     <apex:pageBlockTable value="{!opportunity_proposals__c.Attachments}" var="Att">
     <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!opportunity_proposals__c.for_sendemailwithattachment__c}"/>
        </apex:column>
       <apex:column value="{!Att.createddate}"/>
       <apex:column value="{!Att.name}"/>
       <apex:column value="{!Att.description}"/>
     </apex:pageBlockTable>
     
      </apex:pageBlock>

  </apex:form>
</apex:page>

 

 

 

SMasterSMaster

in addition to my previous message...

 

I am able to send all attachment.. sucessfully.. but not the selected one...

b-Forceb-Force

I didnt get this

 

" I am able to send all attachment.. sucessfully.. but not the selected one... "

 

.

.

.

also how you are selecting the attachment from VF page ?

 

Thanks,

Bala

SMasterSMaster

Hi Bala,

 

The scenario is something like:

 

I have created an apex class, in which i have created a method to to send an email with attachment .

 

then i created another visualforce page, where i am showing all the Notes and Attachment from the related list.... and a commandbutton on which clicking an email gets fired with all attachments... lets say if i have 3 files inside the attachment.. all will go out as an attachment with in one mail....

 

that is working till now...

 

 

 

Now... i need to select an attachment before sending the mail.... and only the selected attachment should go out with in a mail as attachment....

 

please let me now if i am unable to explain...

 

 

SMasterSMaster

Hi Bala,

 

I was trying to implement this (i.e. sent the selected file as attachment within the email) using the wrapper class.. but unable to do so.. here is the code i am using...

 

or, please suggest the suitable solution to resolve this issue.....

 

Apex class:

 

public class Checkbox_Class 

{

 

        public Id oppr     {    get;set;    }         

        public Checkbox_Class(ApexPages.StandardController ctrl)    

        {       

        oppr = ctrl.getRecord().Id;         

        }

       

       

        List<Attachmentwrapper> AttachmentList = new List<Attachmentwrapper>();

        List<Attachment> selectedAttachments = new List<Attachment>();

       

        public List<Attachmentwrapper> getAttachments()

        {

        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])

        {      

            AttachmentList.add(new Attachmentwrapper(a));

            return AttachmentList;

                               

        }

        }

         

        public PageReference getSelected()

        {

           

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

         String[] toAddresses = new String[]{'ashish.garg@headstrong.com'};

         mail.setToAddresses(toAddresses);

         mail.setReplyTo('ashish.garg@headstrong.com');

         mail.setSenderDisplayName('CRM Support');

         mail.setBccSender(false);

         mail.setUseSignature(false);

         mail.setTargetObjectId('005Q0000000FR7f');

         mail.setTemplateId('00XQ0000000QULj');

         mail.saveAsActivity = false;

                          

         //selectedAttachments.clear();

         for(Attachmentwrapper accwrapper : AttachmentList)

         {

         if(accwrapper.selected == true)

         {

         selectedAttachments.add(accwrapper.acc);

         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

         }

         else

         {

         return null;

         }

         }       

        public List<Attachment> GetSelectedAttachments()

        {

            if(selectedAttachments.size()>0)

            return selectedAttachments;

            else

            return null;

        }    

       

        public class Attachmentwrapper

        {

            public Attachment acc{get; set;}

            public Boolean selected {get; set;}

            public Attachmentwrapper(Attachment a)

            {

                acc = a;

               selected = false;

            }

        }

    }

SMasterSMaster
Hi Bala, I hope you must have looked into the code... :) please suggest..
b-Forceb-Force

yap.... I looked into it,

 

 sorry for delayed response give me some time, will post updated controller later on..

 

thanks,

Bala

SMasterSMaster

Hi Bala,

 

i expect you would have looked into the problem... please suggest...

SayasoniSayasoni

Hi sMaster,

I know this post is very old but am trying to implement something similar to this.Did you succeed & if so can you kindly post your final controller?

Thanks in advance.

LalitLalit

Please let me know if you are managed to attach files from notesandattachment section into a visual-force email template.

We have a similar requirement, with sales-form (a custom object) user inset Attachment(contains Rebate check detail or item description).
In Approval e-mail request Accounting/Finance team needs to see all the attached document under Notes&Attachment section. Appreciate any input.

cruttley2cruttley2
I also require this functionality, and I wonder if anyone resolved this?
My users would like to send an email from a custom object, but they would like to attach an attachment from  the list of attachments on the custom object.
Thanks!
SivarajanSivarajan
I am also looking for the same requirement. I try to attach files from attachment in Vf template. it seems like Salesforce does not have this functionality. 

Please share if anyone found
jaya sai prasadjaya sai prasad
Hi,

If you want to send an Email with Attachment a native salesforce app MassMailer DOCS is perfect for you. 
 
MassMailer DOCS let’s you send mass email attachments to your leads or contacts while securely storing your files with Rackspace Cloud Files.

You can try this app by installing from appexchange  -Massmailer Docs

You can learn more details about the product on this website - docs.massmailer.io
Chrystele BenjaminChrystele Benjamin
Hi, I've been trying to get my visualforce email template to attach documents in the opportunity's Notes & Attachments section to the email alert but without success. Has anyone been able to do it successfully?