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
sfdc98sfdc98 

vf email

Hi every one ,tried sending email through vf am not getting any errors and i have given active mail id, but am not receiving the mail when i click on the send button through vf,below is the code..

apex:
public class sendEmailthroughvf {
    public string subject {set;get;}
    public string Body {set;get;}
    List<string>emails=new List<string>{'abc1@gmail.com'};
    
    
    public PageReference sendEmail(){
       
          messaging.SingleEmailMessage mail=new messaging.SingleEmailMessage();
        mail.setSubject(subject);
        mail.setHtmlBody(Body);
        mail.setToAddresses(emails);
        Messaging.SendEmailResult[] r=Messaging.sendEmail(new messaging.SingleEmailMessage[] {mail});
       //Messaging.sendEmail(new Messaging.singleEmailMessage[] { mail });
        return null;
    }
}
vf:

<apex:page controller="sendEmailthroughvf">
    <apex:form >
        <apex:pageBlock >
            <b>Enter Subject:</b> <apex:inputText value="{!subject}"/><p/>
            
                       <b>Enter Body:</b><apex:inputText value="{!Body}"/>
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="send" action="{!sendEmail}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
mukesh guptamukesh gupta
Hi, 

you deliverability setting should be as below screen

User-added image


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
sfdc98sfdc98
Hi mukesh ,thanks for your reply .
settings are same as above screenshot ,acceslevel is All email and Iam not receiving any email.

Thanks
 
mukesh guptamukesh gupta
Hi,

Please try with below code:-

VF page
<apex:page controller="singleEmailExample">
 <apex:form >
Email Address : <apex:inputText value="{!toAddress}" />
 <apex:commandButton value="SendEmail" action="{!sendingEmail}"/> <br/>
  Email Status :<b> {!message}  </b>
 </apex:form>
</apex:page>

singleEmailExample
public class singleEmailExample{    
    public string toAddress{get;set;}
    public string message{get;set;}
    public PageReference sendingEmail(){
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{toAddress};
        semail.setToAddresses(sendingTo);
        //String[] sendingToBccAdd = new String[]{‘XXXX@gmail.com’};
       // semail.setBccAddresses(sendingToBccAdd);
       // String[] sendingTocAdd = new String[]{‘XXXXX@gmail.com’};
      // semail.setCcAddresses(sendingTocAdd); */
        semail.setSubject('Single Email message Example');
        semail.setPlainTextBody('Hello!!!!!This is a test email to test single email message program');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        message='Email Sent !!!';
        return null;
    }
}


 if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh