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

"Portal User Creation" email delivery failed if that portal user created using Apex Code


I've trigger on Quote which create "Portal User" for its associated contact if not exist.
User newPortalUser = new User(Alias = 'AK',
                             EmailEncodingKey = 'UTF-8', 
                             LastName = 'AK', LanguageLocaleKey = 'en_US',
                             LocaleSidKey = 'en_US', 
                             Email = myContact.Email ,
                             ProfileID = myProfile.Id, 
                             ContactId = myContact.Id,
                             TimeZoneSidKey = 'America/Los_Angeles',
                             Username = ''
insert newPortalUser;

Code runs without any error and even Portal User also created in org, but email delivery failed i.e. email address provided while user creation not receives any mail.

Also tried following line of code with above:
Database.DMLOptions dmo = new Database.DMLOptions(); 
dmo.EmailHeader.triggerUserEmail = false; 

​But still result is same. No email delivered to created Portal User.

I also checked "Deliverability" setting under "Email Administration" and Access level is already set to "All mails". 

Is there any other reason of email is not being sent?

Arunkumar RArunkumar R

Can you try out the below link example,

let me know if still you face an issue.
Harpreet On CloudHarpreet On Cloud
Did not "Email Log Files" help? Did it not provide any error? You can check Email Log Files under "Monitoring" in Setup area