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
sunny.kapoor1306sunny.kapoor1306 

How to send mass email?

How to send mass email?

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

----------------vf page -----------------------------

<apex:page controller="test1" id="p">

<script>

function ff()

{

    alert(document.getElementById("p:f:t").value);

}

</script>

<apex:form id="f" >

Enter email id:<apex:inputText value="{!emailid}" id="t" /><br/>

 

<apex:commandButton value="Send Email" action="{!SendEmailvalue}" onclick="ff()"/>

 

</apex:form>

 

</apex:page>

 

---------------- Apex Controller -----------------

 

public class test1 {

 

  public string emailid{get;set;}

 

   public void SendEmailvalue()

   {

   try{

  

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

     for(Integer i=0;i<1000;i++)

     {

         

          string subject='your are registed'+i;

          string body='welcome in sales force address'+i;

          String[] toAddresses = new String[]{emailid};      

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

//           mail.setTemplateId(emailtemp.Id);

  //         mail.setReplyTo(EmailAdd);

           mail.setToAddresses(toAddresses);

          

        mail.setPlainTextBody( body );

         mail.setSaveAsActivity(false);

  //         mail.setwhatId(eMAILvtm.Contact__c);

    //       mail.setTargetObjectId(VTMobj.Contact__c);

           allemail.add(mail);      

        }

     

      Messaging.sendEmail(allemail,false);

      }

      catch(Exception e)

      {

      System.debug('qqqqqqqqqqq'+e);

      }

      }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.