Setting Up Named Credentials for Mailgun Email Gateway
From e2a v3.4967, Mailgun as email gateway won't work by directly putting in the API key under e2a Global Settings. To enable secure integration with Mailgun usage of Named Credentials in Salesforce has been made mandatory. The following step-by-step guide will help you set up Named Credentials for Mailgun. This setup uses External Credentials and Custom Headers to securely manage authentication.
1. Enable Required User Permissions
Before configuring the credentials, ensure the user performing this setup has the appropriate permissions enabled.
-
Visit the Salesforce Help article: Enable External Credential Principal Access
-
Enable the relevant permission for the test user.
-
For Profile: Enabled External Credential Principal Access
-
For Permission Set: External Credential Principal Access
-
2. Create an External Credential
-
From Setup, navigate to:
Setup → Named Credentials → External Credentials -
Click New.
-
Fill in the following fields:
-
Label: mailgun basic auth
-
Name: mailgun_basic_auth
(For namespaced orgs, use: ortoo_e2a__mailgun_basic_auth) -
Authentication Protocol: Select Custom
-
-
Click Save.
3. Create a Named Credential
-
Go to:
Setup → Named Credentials → Named Credentials -
Click New.
-
Enter the following values:
-
Label: mailgun credentials
-
Name: mailgun_credentials
(For namespaced orgs, use: ortoo_e2a__mailgun_credentials) -
URL: https://api.mailgun.net/v3
-
Enabled for Callouts: Checked
-
External Credential: Select mailgun basic auth
-
Generate Authorization Header: Unchecked
-
Allow Formulas in HTTP Header: Checked
-
Allow Formulas in HTTP Body: Checked
-
Allowed Callout Namespaces: Enter ortoo_e2a
-
-
Click Save.
4. Configure Authorization Header in External Credential
-
Return to the External Credential you created in Step-2 with name 'mailgun basic auth':
Setup → Named Credentials → External Credentials
-
Select mailgun basic auth.
-
In the Custom Headers section, click New.
-
Enter the following:
-
Name:
Authorization
-
Value: {!'BASIC ' & BASE64ENCODE(BLOB('api:' & $Credential.mailgun_basic_auth.apikey))}
-
-
Click Save.
5. Create Principal and Authentication Parameter
-
In the mailgun basic auth External Credential page, scroll to Principals and click New.
-
Enter:
-
Parameter Name: All Users
-
-
Click Save.
-
Under the newly created Principal, click Add Authentication Parameter.
-
Enter the following:
-
Name: apikey
-
Value: <Your_Mailgun_API_Key>
-
-
Click Save.
6. Final Step: Add to Global Settings
Ensure that the mailgun_credentials Named Credential is selected under e2a Global Settings within your org to send emails via Mailgun email gateway instead of Salesforce's default email gateway.
Please contact us at support@ortooapps.com for any questions.
★★★★★ - EXCELLENT
★★★★☆ - GOOD
★★★☆☆ - OK
★★☆☆☆ - POOR
★☆☆☆☆ - RUBBISH