-3

MY VFP:::

<apex:page controller="EmailControllerClass">
    <p>
        compose Email:::
    </p>
    <apex:form>
        
        <apex:outputLabel value="Send Email to:" for="To"/>
        <apex:inputText value="{!toMail}" id="To"/><br/>
        
        <apex:outputLabel value="CC Mail to:" for="CC"/>
        <apex:inputText value="{!ccMail}" id="CC"/><br/>
        
        <apex:outputLabel value="Reply Mail to:" for="rep"/>
        <apex:inputText value="{!repMail}" id="rep"/><br/>
        
        <apex:commandButton action="{!senEmail}" value="Send Email"/>
        
        
    </apex:form>
    
</apex:page>

MY APEX CLASS:::

public class EmailControllerClass 
{
    public string toMail{get; set;}
    public string ccMail{get; set;}
    public string repMail{get; set;}
    
    public void sendEmail()
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        
        email.setToAddresses(To);
        if(ccMail!=null && ccMail!='')
            email.setCcAddresses(CC);
        if(repMail!=null && repMail!='')
            email.setInReplyTo(repMail);
        
        email.setSubject('Test Subject');
        email.setPlainTextBody('Plain Text Body');
        
        try
        {
            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
        }
        catch(exception e)
        {
            system.debug(e.getMessage());
        }
    }

}
2
  • 1
    Are you receiving an error? How are you saving these items? Please edit your post to provide complete details. – David Reed Apr 4 at 15:08
  • Did change in code and its woring now string[] To = new string[]{toMail}; string[] CC = new string[]{ccMail}; if(toMail!=null && toMail!='') email.setToAddresses(To); if(ccMail!=null && ccMail!='') email.setCcAddresses(CC); – Akshay Ambhure Apr 4 at 21:01
0

The parameters you're using need to match valid variables.

This means that:

    email.setToAddresses(To);

Should be:

    email.setToAddresses(ToMail);

And:

        email.setCcAddresses(CC);

Should be something like:

        email.setCcAddresses(ccMail.split(','));
1
  • Thanks you ...I did change string[] To = new string[]{toMail}; string[] CC = new string[]{ccMail}; if(toMail!=null && toMail!='') email.setToAddresses(To); if(ccMail!=null && ccMail!='') email.setCcAddresses(CC); – Akshay Ambhure Apr 4 at 20:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.