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
Aishwarya P 4Aishwarya P 4 

How to access the dymaic email id in the message.toaddresses?

This is the class :

public class emailid
{
    
    public string emailidnoti{get;set;}
             
    public emailid() 
    {
    }
    public emailid(ApexPages.StandardController controller)
    {
    }   
    public void sendnotification()
    {
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.toAddresses = new String[] { ???????}
        message.subject = 'Email Notification From XYZ Page';
        message.plainTextBody = 'Hello !! Your Business Details were successfully displayed';
        Messaging.SingleEmailMessage[] messages =   new List<Messaging.SingleEmailMessage> {message};
        Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
    }
}

This is the visualforce code :

<apex:page sidebar="false" showHeader="False" standardStylesheets="false">
     <style>
        .myFormStyle
        {
            background-color : #FEF9E7;
             margin: auto;
            width: 50%;
            border: 3px solid green;
            padding: 10px;            
        }
        
    </style>
       <apex:form styleClass="myFormStyle">
       <center><h1>Welcome To The Page </h1></center>
       <center><h3><b><u><i> {! $user.FirstName} </i></u></b></h3></center> <br/>
       <apex:pageBlock>
       <p4><font size="2" color="Red"><font color="Black">NAME : </font> {! $user.FirstName}</font></p4><br/>
       <p4><font size="2" color="Red"><font color="Black">EMAIL-ID :</font> {! $user.Email} </font></p4><br/>
       </apex:pageBlock> 
       <apex:pageBlock title="Email">
       <apex:commandButton action="{!sendnotification}" value="Send Notification"/>
       </apex:pageBlock>
       </apex:form>

</apex:page>

How to send the email to the user ?
How to access the user's email id in the To address?
sandeep madhavsandeep madhav

Hi,

Hope this helps,

1.Create a list of string and add email to the list.
2. message.toAddresses = new String[] {stringList}

list<String> emials_lst = new list<string>()

emials_lst.put(email);
message.toAddresses = new String[] {emials_lst}

 

 

Aishwarya P 4Aishwarya P 4
Nope. Not working