1

I have created an LWC with a form by collecting the basic info, Then i will be sending the info to the email service.

Below is the code

 string emailAddress = GetEmailServiceAddressUtility.getemailServiceAddress('Enrollment');
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            string[] to = new string[] {emailAddress}; 
                email.setToAddresses(to);
            email.setInReplyTo('[email protected]');            
            email.setSubject('New Enrollment' + ';' + formId);            
            email.setHtmlBody(strObject + '~~~~EnrollmentTermCondition~~~~' + term);            
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });

This email is not received from the guest user, but when I tried from SYStem admin It worked.

tried the below code too

Messaging.SingleEmailMessage emailtest = new Messaging.SingleEmailMessage();
            emailtest.setToAddresses(new String[] { '[email protected]' }); // Please add your email id here
            emailtest.setSubject('my subject');
            emailtest.setPlainTextBody('plain text body');
            List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[] { emailtest });
            
            if (results[0].success)
            {
                System.debug('The email was sent successfully.');
            }
            else
            {
                System.debug('The email failed to send: '      + results[0].errors[0].message);
            }

In debug log I can see this 'The email was sent successfully.' message but email not received.

Note:

  1. Checked in Deliverability Access level set as ALL Email
  2. Send Email permission is enabled for Guest User.

Please let me know anything which I am missing here.

2
  • 1
    Have you looked in the email logs files?
    – Nick C
    Jun 28, 2022 at 3:07
  • @NickCook Yes Its Showing R in the Mail Event column
    – SK2889
    Jun 28, 2022 at 12:13

1 Answer 1

1

As per this article Sending Email as Guest User Fails Even When the Profile Has the Appropriate Permissions:

As of the Summer '21 release newly created Experience Sites no longer assign to the guest user the email address of the Administrator that created the site. A fake email address is now assigned to the guest user record. If you encounter this issue please navigate to the Guest User record for the affected site and update the Guest User email address with a valid email address.

Check the guest user email address, it is most probably invalid, which most probably explain why the email is not sent because from address (guest user email) is not valid

2
  • @user3214361 did you get the chance to check if this resolve your issue ?
    – Shamina
    Jul 21, 2022 at 15:48
  • are you facing this issue?
    – Gopal
    May 16, 2023 at 8:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .