[SalesForce] New Customer Portal user email even when triggerUserEmail = false

I'm trying to write an Apex web service that can create a customer portal user. After creating the user, there is a separate step which does a password reset for the user and sends them an email.

The problem I'm running into is that Salesforce is automatically sending the user an email when the Contact and User are created. I want to prevent this so I can send the email later after setting their password.

I've tried the code below, which sounds like it should work according to the docs.

Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = false;
dlo.EmailHeader.triggerAutoResponseEmail = false;
dlo.EmailHeader.triggerOtherEmail = false;

...
contact.setOptions(dlo);
Database.insert(contact, dlo);

...
user.setOptions(dlo);
Database.insert(user, dlo);

Unfortunately, each time I create a user with the webservice I'm still receiving an email from Salesforce, despite setting these flags on DMLOptions…

Does anybody know of a solution which will prevent this from happening?

Edit: I also tried with Site.createPortalUser(user, acctId, null, false). This didn't work for the following reason:

System.TypeException: That operation is only allowed from within an active site.

Best Answer

After further investigation and running some debug logs, I found that our org had a managed trigger that was firing when the User record was being inserted.

We were not able to determine exactly what the trigger was doing (as it was managed code), but after disabling it the email is no longer being sent from Salesforce, and DMLOptions now appears to be working as expected.