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
SamirSSamirS 

Send email from apex through Gmail account

I built a lightning application, where I used a button to send mail. Currently, it is working fine through SingleEmailMessage Methods.
Messaging.SingleEmailMessage mail1 = new Messaging.SingleEmailMessage();

    List<OrgWideEmailAddress> owaList = [select id, Address from OrgWideEmailAddress where DisplayName = 'Sam Test'];
    if(owaList.size()>0)
    {
        mail1.setOrgWideEmailAddressId(owaList.get(0).id);
    }

    mail1.setUseSignature(false);
    mail1.setToAddresses(new String[] { PMEmail });
    mail1.setReplyTo(owaList.get(0).Address); 
    mail1.setSubject(ProjectSubjectPickup);
    mail1.setHtmlBody(EmailBody1);
    mail1.setFileAttachments(new Messaging.EmailFileAttachment[] { attachMail1 });
    system.debug('<===>mail1' + mail1); 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail1 });
Can I send this email through / via my Gmail account? Salesforce has a feature like "Send through External Email Services", and I already did the integration with my Gmail account. But it is not applicable for the SingleEmailMessage service. Can someone please help me with this?