+ Start a Discussion
Akhil R NathAkhil R Nath 

I am writing this code to send email through apex, I want to send email to Opportunity related contacts. Can someone help me on that?

public with sharing class MultipleSearchObjects {
    public Account acc{get;set;}
    public Contact con{get;set;}
    public Opportunity opp{get;set;}
    public Lead ld{get;set;}
    public List<Account> accountList {get;set;}
    public List<Contact> contactList {get;set;}
    public List<Opportunity> oppList {get;set;}
    public List<Lead> ledList{get;set;}
    public String selectedSObject {get;set;}
     public List<SelectOption> objects = new List<SelectOption>();
      public List<SelectOption> options = new List<SelectOption>();
    public List<String> recordList {get;set;}
    public String selectedRecord {get;set;}
    public boolean pb1Rendered{get;set;}
    public boolean pb2Rendered{get;set;}
    public boolean pb3Rendered{get;set;}
    public String RES { get; set; }
    public String body { get; set; }
    public String send{get;set;}
    public String Folder { get; set; }
    public String Cc { get; set; }
    public String subject { get; set; }
    public  string template{get;set;}
    public string strQueryLd;
    public EmailTemplate et{get;set;}
    public string selectedTemplate;

    public Contact con1{get;set;}
            public Set<Id> contactIdSet = new Set<Id>();
    // create a list of strings to hold the conditions
    public List<string> conditions = new List<string>();
    List<Date> dates= new List<Date>();
    private integer totalRecs = 0;
    private integer OffsetSize = 0;
    private integer LimitSize= 10;
    
    public MultipleSearchObjects(){
        system.debug('==>AccountMultipleSearchWithPagenationCLS  is calling==>');
        acc = new Account();
        con = new Contact();
        ld  = new Lead();
        opp = new Opportunity();
        contactList = new List<Contact>();
        ledList = new List<Lead>();
        oppList = new List<Opportunity>();
        //accLd = new list<Lead>();
        pb1Rendered =pb2Rendered = pb3Rendered = false;
        selectedSObject = '';
        //accountList  = new List<Account>();
    }
      public PageReference refresh() {
        return null;
    }
    public void preview(){
        system.debug('text');
        // do nothing
    }
    
        public void searchCon(){
        totalRecs = 0;
        OffsetSize = 0;
        if(contactList !=null && contactList.size()>0){
            contactList=null;
        }
        searchContacts ();
        conditions.clear();
    }
      public void searchLd(){
        totalRecs = 0;
        OffsetSize = 0;
        if(ledList !=null && ledList.size()>0){
            ledList=null;
        }
        searchLeads();
        conditions.clear();
    }


    
     public void onChangeFnCall(){
        if(selectedSObject== 'Contact'){
            pb2Rendered = true;
            pb3Rendered = false;
            pb1Rendered = false;
        }
        else if(selectedSObject== 'Lead'){
            pb2Rendered = false;
            pb3Rendered = true;
            pb1Rendered = false;
        }
        else if(selectedSObject == 'Opportunity'){
            pb2Rendered = false;
            pb3Rendered = false;
            pb1Rendered = true;
        }
    }
    
     public void FirstPage()
    {
        OffsetSize = 0;
        //searchContacts();
        //searchLeads();
        system.debug('Hello');
        

        
    }
    public void previous()
    {
        OffsetSize = (OffsetSize-LimitSize);
        //searchContacts();
        //searchLeads();
        system.debug('Hello');
    }
    public void next()
    {
        OffsetSize = OffsetSize + LimitSize;
        //searchContacts();
        //searchLeads();
        system.debug('OffsetSize'+OffsetSize);
    }
    public void LastPage()
    {
        OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
        //searchContacts();
        //searchLeads();
    }
    public boolean getprev()
    {
        
        if(OffsetSize == 0){
            
            return true;
        }
        else {
            
            return false;
        }
    }
    public boolean getnxt()
    {
        if((OffsetSize + LimitSize) > totalRecs){
            
            return true;
        }
        else {
            
            return false;
        }
    }
    public void searchAcc(){
        totalRecs = 0;
        OffsetSize = 0;
        if(accountList !=null && accountList.size()>0){
            accountList=null;
        }
        searchAccounts ();
        conditions.clear();
    }
  
     public List<SelectOption> getSObjectNames(){
       objects.add(new SelectOption('','Select'));
       objects.add(new SelectOption('Account','Account'));
       objects.add(new SelectOption('Lead','Lead'));
       objects.add(new SelectOption('Opportunity','Opportunity'));
       objects.add(new SelectOption('Contact','Contact'));
            system.debug('objects'+objects);
       return objects;
           
    
    }
    
    public Void searchOpp(){
        
        System.debug('Total Records is ==>'+totalRecs);
        System.debug('OffsetSize is ==>'+OffsetSize);
        
        if(oppList != null && !oppList.isEmpty()){
            oppList.clear();
        }
        String strQueryopp ='SELECT Name, StageName,Type,Industry__c, FiscalYear, Country__c,Category_interested_in2__c,CloseDate,Shipped_Status__c From Opportunity';
        if(opp.CreatedById !=null){
            String fromDate = opp.CreatedById+'';
            fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z';
            conditions.add('CreatedDate >='+fromDate);
        }
        
        if(opp.CreatedById !=null){
            String toDate = opp.CreatedById+'';
            toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z';
            conditions.add('createdDate <='+toDate);
        }
        
        if(opp.StageName !=null && opp.StageName !=''){
            conditions.add('StageName Like \'%' +opp.StageName +'%\' ');
        }
         
        if(opp.Type !=null && opp.Type !=''){
            conditions.add('Type Like\'%' +opp.Type +'%\' ');
        }
        if(opp.Industry__c !=null && opp.Industry__c !=''){
            conditions.add('Industry__c Like\'%' +opp.Industry__c +'%\' ');
        }
          if(opp.Country__c !=null && opp.Country__c !=''){
            conditions.add('Country__c Like\'%' +opp.Country__c +'%\' ');
        }
        if(opp.Category_interested_in2__c !=null && opp.Category_interested_in2__c !=''){
            conditions.add('Category_interested_in2__c Like\'%' +opp.Category_interested_in2__c +'%\' ');
        }
         //if(opp.CloseDate !=null && opp.CloseDate !=''){
           // conditions.add('CloseDate Like\'%' +opp.CloseDate +'%\' ');
        //}
        if(opp.Shipped_Status__c !=null && opp.Shipped_Status__c !=''){
            conditions.add('Shipped_Status__c Like\'%' +opp.Shipped_Status__c +'%\' ');
        }
        
        
        
        if (conditions.size() > 0) {
            strQueryopp += '  WHERE ' + conditions[0];
            for (Integer i = 1; i < conditions.size(); i++)
                strQueryopp += '  AND ' + conditions[i];
        }
        if(totalRecs !=null && totalRecs ==0){
            List<Opportunity> accOpp = Database.query(strQueryopp);
            totalRecs = (accOpp !=null &&accOpp.size()>0)?accOpp.size():0;
        }
        
        system.debug('strQueryopp ==>'+strQueryopp );
        // add sort and limits at the end  
        strQueryopp += ' ORDER BY Name  ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize';
        
        oppList  =Database.query(strQueryopp);
        
        
        
        //conditions.clear();
        //return accountList.size();
    }


    public void searchContacts(){
        
        System.debug('Total Records is ==>'+totalRecs);
        System.debug('OffsetSize is ==>'+OffsetSize);
        
        if(contactList != null && !contactList.isEmpty()){
            contactList.clear();
        }
        String strQueryCon ='SELECT Id,Email,LeadSource, AccountId, Name,Phone  From Contact';
        if(con.CreatedById !=null){
            String fromDate = con.CreatedById+'';
            fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z';
            conditions.add('CreatedDate >='+fromDate);
        }
        
        if(con.AccountId !=null){
            String toDate = con.AccountId+'';
            toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z';
            conditions.add('createdDate <='+toDate);
        }
        
        if(con.Name !=null && con.Name !=''){
            conditions.add('Name Like \'%' +con.Name +'%\' ');
        }
        if(con.Email !=null && con.Email !=''){
            conditions.add('Email Like\'%' +con.Email +'%\' ');
        }
        if(con.Phone !=null && con.Phone !=''){
            conditions.add('Phone Like\'%' +con.Phone +'%\' ');
        }
        if(con.LeadSource !=null && con.LeadSource !=''){
            conditions.add('LeadSource Like\'%' +con.LeadSource +'%\' ');
        }

        
        if (conditions.size() > 0) {
            strQueryCon += '  WHERE ' + conditions[0];
            for (Integer i = 1; i < conditions.size(); i++)
                strQueryCon += '  AND ' + conditions[i];
        }
        if(totalRecs !=null && totalRecs ==0){
            List<Contact> accCon = Database.query(strQueryCon);
            totalRecs = (accCon !=null &&accCon.size()>0)?accCon.size():0;
        }
        
        system.debug('strQueryCon ==>'+strQueryCon );
        // add sort and limits at the end  
        strQueryCon += ' ORDER BY Name  ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize';
        
        contactList  =Database.query(strQueryCon);
        system.debug('contactList'+contactList);
        
         //pb1Rendered = true;

        //return null;
        //conditions.clear();
        //return accountList.size();
    }
    
     public Void searchLeads(){
        
        System.debug('Total Records is ==>'+totalRecs);
        System.debug('OffsetSize is ==>'+OffsetSize);
        
        if(ledList != null && !ledList.isEmpty()){
            ledList.clear();
        }
        String strQueryLd ='SELECT Name, Status,Category_interested_in__c,Category_Type__c,Country__c,LeadSource,Industry From Lead';
        if(ld.CreatedById !=null){
            String fromDate = ld.CreatedById+'';
            fromDate = fromDate.split(' ',0)[0]+'T00:00:00.000Z';
            conditions.add('CreatedDate >='+fromDate);
        }
        
        //if(ld.AccountId !=null){
            //String toDate = ld.AccountId+'';
            //toDate = toDate.split(' ',0)[0]+'T23:59:59.000Z';
            //conditions.add('createdDate <='+toDate);
        //}
        
        if(ld.Name !=null && ld.Name !=''){
            conditions.add('Name Like \'%' +ld.Name +'%\' ');
        }
        if(ld.Status !=null && ld.Status !=''){
            conditions.add('Status Like\'%' +ld.Status +'%\' ');
        }
        if(ld.Category_interested_in__c !=null && ld.Category_interested_in__c !=''){
            conditions.add('Category_interested_in__c Like\'%' +ld.Category_interested_in__c +'%\' ');
        }
        if(ld.LeadSource !=null && ld.LeadSource !=''){
            conditions.add('LeadSource Like\'%' +ld.LeadSource +'%\' ');
        }
          if(ld.Category_Type__c !=null && ld.Category_Type__c !=''){
            conditions.add('Category_Type__c Like\'%' +ld.Category_Type__c +'%\' ');
        }
          if(ld.Country__c !=null && ld.Country__c !=''){
            conditions.add('Country__c Like\'%' +ld.Country__c +'%\' ');
        }
          if(ld.Industry !=null && ld.Industry !=''){
            conditions.add('Industry Like\'%' +ld.Industry +'%\' ');
        }

        
        if (conditions.size() > 0) {
            strQueryLd += '  WHERE ' + conditions[0];
            for (Integer i = 1; i < conditions.size(); i++)
                strQueryLd += '  AND ' + conditions[i];
        }
        if(totalRecs !=null && totalRecs ==0){
            List<Lead> accLd = Database.query(strQueryLd);
            totalRecs = (accLd !=null &&accLd.size()>0)?accLd.size():0;
        }
        system.debug('strQueryLd ==>'+strQueryLd );
        // add sort and limits at the end  
        strQueryLd += ' ORDER BY Name  ASC, CreatedDate DESC LIMIT :LimitSize OFFSET :OffsetSize';
        
        ledList  =Database.query(strQueryLd);
         system.debug('ledList'+ledList);
        
        
        
        //conditions.clear();
        //return accountList.size();
    }
    
    public list<selectoption> getdw(){
        
        List<SelectOption> options = new List<SelectOption>();
        List<Folder> Folders = [Select Id, Name From Folder Where type = 'Email'];
        for(Folder F : Folders){  
            options.add(new SelectOption(F.Name, F.Name));
            //options.add(new selectOption('F.Unified public Email Template','F.Unified public Email Template'));
            //options.add(new selectOption('F.My Personal Email Template ','F.My Personal Email Template'));
        }
        return options;
    }
    
    public list<selectoption> getName() {
        
        List<SelectOption> options = new List<SelectOption>();
        List<EmailTemplate> et = [SELECT Id,Name, DeveloperName, FolderId, Folder.DeveloperName FROM EmailTemplate ];
        for( EmailTemplate  e : et)
        {
            options.add(new SelectOption(e.id, e.Name));
        }
        return options;
    }
    public void send(){
         //List<contact> lstcon=[Select id from contact];
       List<Id> lstids= new List<Id>();
         system.debug('lstIds'+lstIds);
        system.debug('lstids'+lstids);
        for(Contact c:contactList)
        {
            lstIds.add(c.id);
        }
        //List<Lead> lstld= [Select id, Name from Lead];
        //system.debug('lstld'+lstld);
        system.debug('ledList'+ledList);
        for(Lead l:ledList)
        {
            lstIds.add(l.id);
        }
          for(Opportunity o:oppList)
        {
            lstIds.add(o.id);
        }
         
       
        EmailTemplate et1=[SELECT Id,Name, DeveloperName, FolderId, Folder.DeveloperName FROM EmailTemplate limit 1];
        system.debug('et'+et);
        
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(lstIds);
        system.debug('lstIds'+lstIds);
        mail.setSenderDisplayName('System Admin');
        mail.setTemplateId(et1.id);
        Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
    }
}


 
ShirishaShirisha (Salesforce Developers) 
Hi Akhil,

Greetings!

It is very difficult for us to troubleshoot the code that you have above.However,I can provide you the suggestions which will help you in either creating the flow/trigger to achieve your requirement.

For the Trigger:
================
The contact roles table is a layer of indirection from the Opportunity table, that's why it can't find an email on it -- the contact role doesn't actually have any email on it per se, the linked contact does.

I think your best option is to make a lookup to Contact from Opportunity.  You could then copy the primary contact role to that custom field using a trigger like this (see the one marked as the solution).  Then your email alert would be able to see that contact's email address.

Note that such a trigger would not work retroactively, only for opportunities that are changed after you've set your trigger.

If you would like to create flow:
=========================
Use the following to whip up something on your own and let us know if you face any trouble along the way:
http://judisohn.com/2015/04/06/using-salesforce-process-builder-flow-with-opportunity-contact-roles/

An existing post to help you with it (similar implementations):
https://success.salesforce.com/answers?id=9063000000048Tc

And feel free to upvote the idea here:
https://success.salesforce.com/ideaview?id=08730000000BrHdAAK

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Akhil R NathAkhil R Nath
Hi Shirisha,

I have changed the code like this and it will send emails related to Opportunity.
I have an issue in pagination which I couldn't rectify it because when search records are showing fine. but clicking on the next page it is not going to next page. Any Suggestions? Thanks in Advance.
    public void send(){
        //contList= new List<Contact>();
         List<Contact> lstop=[SELECT Id, Name FROM Contact WHERE AccountId IN (SELECT AccountId FROM Opportunity WHERE Id = :oppList) ];
       List<Id> lstids= new List<Id>();
         List<Id> oppids= new List<Id>();
         system.debug('lstIds'+lstIds);
        system.debug('lstids'+lstids);
        for(Contact c:contactList)
        {
            lstIds.add(c.id);
        }
        //List<Lead> lstld= [Select id, Name from Lead];
        //system.debug('lstld'+lstld);
        system.debug('ledList'+ledList);
        for(Lead l:ledList)
        {
            lstIds.add(l.id);
        }
        
         for(Contact o:lstop)
        {
            lstIds.add(o.id);
        }
         
         
        if(lstIds.size()>0) {    
        EmailTemplate et1=[SELECT Id,Name, DeveloperName, FolderId, Folder.DeveloperName FROM EmailTemplate Where Id =:selectedEmailTemplate limit 1];
        system.debug('et'+et);
        
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        //mail.whatids(oppids);
        mail.setTargetObjectIds(lstIds);
        system.debug('lstIds'+lstIds);
        mail.setSenderDisplayName('System Admin');
        mail.setTemplateId(et1.id);
        Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
    }
    }
}


<apex:page controller="MultipleSearchObjects" id="page" >
    <script type="text/javascript">
    window.onload=function() {
        // document.getElementById("{!$Component.thePb.thepbs.accName}").focus();
    }   
    </script>
    <apex:form id="frm" >
        <apex:actionRegion >
            <!--<apex:selectList label="Select Object Name" title="Select Object Name" multiselect="false" value="{!selectedSObject}" size="1">
<apex:actionSupport event="onchange" action="{!onChangeFnCall}"/> 
<apex:selectOptions value="{!SObjectNames}" /> 
</apex:selectList>
<apex:dataList id="output" value="{!recordList}" var="r">
{!r}
</apex:dataList>-->
        </apex:actionRegion>
        <apex:selectList value="{!selectedSObject}" size="1" multiselect="false">
            <apex:selectOption itemValue="" itemlabel="--None--"/>
            <apex:selectOption itemValue="contact" itemlabel="Contact"/>
            <apex:selectOption itemValue="lead" itemlabel="Lead"/>
            <apex:selectOption itemValue="opportunity" itemlabel="Opportunity"/>
            <apex:actionSupport event="onchange" action="{!onChangeFnCall}"  rendered="true" />
        </apex:selectList>
        
        <apex:outputPanel id="dts"  rendered="{!pb2Rendered}" >
            <apex:pageBlock id="pageForm" title="Contact Details To Search" >
                <apex:pageblockSection id="Pgform">
                    <apex:inputField id="cmail" value="{!con.Email}" />
                    <apex:inputField id="cledsr" value="{!con.LeadSource}"/>
                    <apex:inputField id="caccId" value="{!con.AccountId}"/>
                    <apex:inputfield id="cphn" value="{!con.Phone}"/>
                    <apex:inputfield id="cname" value="{!con.Name}"/>
                    
                </apex:pageblockSection>
                <apex:pageblockButtons location="bottom">
                    <apex:commandButton value="Search"  action="{!searchContacts}" />
                       <apex:commandButton value="Reset" action="{!reset}"/>
                    <apex:commandButton value="Clear" action="{!clear}"/>
                </apex:pageblockButtons>  
            </apex:pageBlock>
        </apex:outputPanel>
        
        <apex:outputPanel id="dts3"  rendered="{!pb2Rendered}">
            <apex:pageBlock title="Contact">
                <apex:pageBlockTable value="{!contactList}"  var="a">
                    <apex:column value="{!a.Email}" headerValue="Email"/>  
                    <apex:column value="{!a.LeadSource}" headerValue="Lead Source"/>  
                    <apex:column value="{!a.AccountId}" headerValue="Annual Revenue"/>  
                    <apex:column value="{!a.Phone}" headerValue="Phone"/>   
                    <apex:column value="{!a.Name}" headerValue="Name"/>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:outputPanel>
        
        <apex:outputPanel id="dts1"  rendered="{!pb3Rendered}">
            <apex:pageBlock id="pageForm1" title="Lead Details To Search" >
                <apex:pageblockSection >
                    <apex:inputField value="{!ld.Status}"/>
                    <apex:inputField value="{!ld.Category_interested_in__c}"/>
                    <apex:inputField value="{!ld.Category_Type__c}"/>
                    <apex:inputfield value="{!ld.Country__c}"/>
                    <apex:inputfield value="{!ld.LeadSource}"/>
                    <apex:inputfield value="{!ld.Industry}"/>
                    
                    
                </apex:pageblockSection>
                <apex:pageblockButtons location="bottom">
                    <apex:commandButton value="Search" action="{!searchLeads}" />
                                    <apex:commandButton value="Reset" action="{!reset}"/>
                    <apex:commandButton value="Clear" action="{!clear}" />

                </apex:pageblockButtons>  
            </apex:pageBlock>
        </apex:outputPanel>
        <apex:outputPanel id="dts05"  rendered="{!pb3Rendered}">
            <apex:pageBlock title="Lead">
                <apex:pageBlockTable value="{!ledList}"  var="a">
                    <apex:column value="{!a.Status}" headerValue="Status"/>  
                    <apex:column value="{!a.Category_interested_in__c}" headerValue="Category Interested In"/>  
                    <apex:column value="{!a.Category_Type__c}" headerValue="Category Type"/>  
                    <apex:column value="{!a.Country__c}" headerValue="Country"/>   
                    <apex:column value="{!a.LeadSource}" headerValue="Lead Source"/>
                    <apex:column value="{!a.Industry}" headerValue="Industry"/> 
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:outputPanel>
        
        <apex:outputPanel id="dts2"  rendered="{!pb1Rendered}">
            <apex:pageBlock id="thePlOpp" title="Opportunity Details To Search">
                <apex:pageblockSection id="theplOp">
                    <apex:inputField value="{!opp.StageName}" />
                    <apex:inputField value="{!opp.Type}"/>
                    <apex:inputField value="{!opp.Industry__c}"/>
                    <apex:inputfield value="{!opp.Country__c}"/>
                    <apex:inputfield value="{!opp.Category_interested_in2__c}"/>
                    <apex:inputfield value="{!opp.Shipped_Status__c}"/>
                    <apex:inputfield value="{!opp.CloseDate}"/>
                </apex:pageblockSection>
                <apex:pageblockButtons location="bottom">
                    <apex:commandButton value="Search" action="{!searchOpp}" />
                       <apex:commandButton value="Reset" action="{!reset}"/>
                    <apex:commandButton value="Clear" action="{!clear}"/>
                </apex:pageblockButtons>  
            </apex:pageBlock>
        </apex:outputPanel>
        
        <apex:outputPanel id="dts03"  rendered="{!pb1Rendered}">
            <apex:pageBlock title="Opportunity">
                <apex:pageBlockTable value="{!oppList}"  var="a">
                    <apex:column value="{!a.StageName}" headerValue="Stage"/>  
                    <apex:column value="{!a.Type}" headerValue="Type"/>  
                    <apex:column value="{!a.Industry__c}" headerValue="Industry"/>  
                    <apex:column value="{!a.Country__c}" headerValue="Country"/>   
                    <apex:column value="{!a.Category_interested_in2__c}" headerValue="Category Interested In"/>
                    <apex:column value="{!a.Shipped_Status__c}" headerValue="Shipped Status"/> 
                    <apex:column value="{!a.CloseDate}" headerValue="Closed Date" />
                    
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:outputPanel>
        
    
   <apex:pageBlock >
       
       

         <apex:pageblockButtons >
                    <apex:commandButton value="First Page" rerender="details"  action="{!FirstPage}" disabled="{!prev}"/>
                    <apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
                    <apex:commandButton value="Next" rerender="details" action="{!next}" onclick="Next" disabled="{!nxt}"/>
                    <apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
                
                </apex:pageblockButtons>
                
   <apex:outputPanel id="otp1" rendered="{!pb4Rendered}">
  <apex:pageBlock title="View Email Template" id="emailTemplateBlock">
            Select Email Template Folder:
            <apex:selectList value="{!selectedEmailTemplateFolder}" multiselect="false" size="1">
                <apex:selectOptions value="{!emailTemplateFolderOpts}" />
                <apex:actionSupport event="onchange" action="{!refreshEmailTemplateSection}" rerender="emailTemplateBlock" />
            </apex:selectList>
            <br/>
            Select Email Template: 
            <apex:selectList value="{!selectedEmailTemplate}" multiselect="false" size="1">
                <apex:selectOptions value="{!emailTemplateOpts}" />
                <apex:actionSupport event="onchange" action="{!refreshEmailTemplateSection}" rerender="emailTemplateBlock" />
            </apex:selectList>
            <br/>
            <apex:outputPanel id="emailTemplateContentPanel" rendered="{!NOT(ISNULL(chosenEmailTemplate))}" >
                <p><b>{!chosenEmailTemplate.Name} - Subject:</b> {!chosenEmailTemplate.Subject}</p>
                <pre>{!chosenEmailTemplate.Body}</pre>
            </apex:outputPanel>
        </apex:pageBlock>
       </apex:outputPanel>
<apex:commandButton action="{!send}" value="SEND"/>
 
</apex:pageBlock>
          
    </apex:form>
   
</apex:page>