I built a lightning component with an email sending feature. It is working correctly through Salesforce internal Email service. But I have a requirement to send email through my Gmail account just like the salesforce has the inbuilt feature "My Email Settings" and "Send through External Email Services". But this feature is not working with the lightning component. I want to implement this below feature through Apex and lightning component.

enter image description here

Please help me with any suggestions or resources on this.

enter image description here

Here is my Apex code snippet-

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

    List<OrgWideEmailAddress> owaList = [select id, Address from OrgWideEmailAddress where DisplayName = 'Sam Test'];

    mail1.setToAddresses(new String[] { PMEmail });
    mail1.setFileAttachments(new Messaging.EmailFileAttachment[] { attachMail1 });
    system.debug('<===>mail1' + mail1); 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail1 });
  • Check this link : trailhead.salesforce.com/en/content/learn/modules/… – RedDevil Dec 3 '19 at 5:42
  • Thanks for the reply. But It is for Salesforce integrated feature that I have mentioned. Emails sent through workflows and triggers are still sent through Salesforce. I want this in apex. – Sam Dec 3 '19 at 5:49
  • Hey there Have you checked the user permission "Send email through external Email Services" and/or and have you integrated it completely? – KDH Dec 3 '19 at 5:54
  • Currently "Send email through external Email Services" feature is working fine in my sandbox. What type of permission you are referring to? – Sam Dec 3 '19 at 5:58
  • There is a permission on profile that allows a user to send through external services but I believe it is checked by default so it should be fine. Maybe if you posted your lightning component code we could help you better – KDH Dec 3 '19 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.