Join us
@sofiatarhonska ・ Jun 20,2023 ・ 10 min read ・ 881 views ・ Originally posted on mailtrap.io
While Salesforce’s testing capabilities are sufficient for running small deliverability tests or previewing your emails, they may not be enough for inspecting and debugging emails in detail. Plus, some methods may bear the risk of spamming contacts with test emails.
That’s where Mailtrap Email Testing comes into play. And today, we’ll teach you how to execute various tests in Salesforce using Mailtrap.
Mailtrap Email Testing is an Email Sandbox – a safe environment to inspect and debug emails in staging and development environments. It captures all the SMTP traffic and traps your test emails in a virtual inbox. Email Testing is part of the Mailtrap Email Delivery Platform.
Some of the features of Email Testing include
There are several use cases where you should opt for Mailtrap Email Testing. Let’s quickly discuss each of them below.
You can easily avoid annoying your recipients by using Mailtrap Email Testing. It will create sort of a barrier between Salesforce and your contacts. As a result, all your test emails will end up in a virtual inbox.
With Email Testing, you can easily check HTML/CSS in your templates for different email clients. You’ll see a detailed chart with problematic lines of code marked in red. Each problematic element has a description of the support level for each client.
On top of that, Email Testing has a Spam Analysis feature.
The feature is particularly important for your deliverability and sender reputation. Why? The score gives you a clear indication if mailbox providers may automatically label your email template as spam. Plus, you get to see if your domain or IP appear in any of the blacklists.
That way, you’ll get the chance to make the emails less spammy in staging and protect your sender reputation in production.
Email Testing captures all your outgoing Salesforce emails and keeps them organized in different inboxes for various projects and testing stages.
So, Email Testing and Salesforce create a robust combo for in-depth testing and debugging.
For the instructions below, we’ll assume that you already have a Salesforce account up and running.
But to start testing, you’ll also need to set up a Mailtrap account (if you have it already, you can skip this step).
2. Go to Email Testing → Inboxes to find your first inbox created by default. It’s called ‘My Inbox’ but you can easily rename it by clicking the pencil icon on the right. It’s also possible to create additional projects and inboxes if needed.
3. Click on your inbox and hit Show Credentials to reveal the credentials for the fake SMTP server.
4. Go to your Salesforce account and navigate to Setup → Email (under Administration) → Email Relays.
5. Click Create Email Relay and fill out the form with Email Testing’s SMTP credentials as in the example below:
6. Click Enable SMTP Auth to connect to the SMTP server with authentication. Enter your SMTP username and password.
7. Click Save. Head to Email Domain Filters and click Create Email Domain Filter. This step is necessary to activate the relay.
8. There, enter ‘*’ as the default wildcard for Sender Domain and Recipient Domain. Then mark the Active checkbox, otherwise the relay won’t be applied. Click Save.
Now it’s time to send test emails with Apex and see if they will be delivered to the Email Testing’s virtual inbox. For more details on sending emails with Apex, check out this blog post.
In your Salesforce account, navigate to Setup and type Apex Classes in a quick find box.
Click New to create a new Apex class that will send a simple email. Paste the following snippet and press Save.
Don’t forget to substitute recipient@example.com and no-reply@example.com with actual email addresses.
Go back to the Apex classes page, click Developer Console, and open the class we just created. Under debug, choose Open Execute Anonymous Window.
Type the following line of code and click Execute.
Under logs, a success message will appear. Head to your Mailtrap Email Testing inbox and you’ll see the test email there. This confirms that Salesforce deliverability doesn’t have any issues.
Testing email templates is quite easy in Salesforce. And since we already have email relay configured, we just need to take a couple of additional steps. To make our tests interesting and leverage the full capabilities of Email Testing, let’s send text and HTML templates separately.
1.We’ll create a sample text template in Salesforce. Go to Setup → Email → Classic Email Templates and click New Template.
2.Select Text as the template type and press Next.
3.Configure the desired merged fields. For this example, we chose Contact Fields as the field type and the First Name as the field. Then, choose the folder in which the template will be saved, mark the checkbox next to Available For Use, name the template, and enter the subject line and body text. Don’t forget to insert the auto-generated merge field. Save the template.
4.Click Send Test and Verify Merge Fields.
5.In the pop-up window, choose the contact you want to test the template for. Tick Send email preview to and enter your email address.
6.Click OK. Now check your Email Testing inbox. The test template will be right there. However, you won’t find it in your real inbox since we sent it through the fake SMTP server.
Just like in the previous example, we should start by creating a template, but instead of text, let’s select Custom (without using Classic Letterhead). Click Next.
Select the folder, make the template available for use, give it a unique name, and set the subject. The Encoding should be set to Unicode (UTF-8) as per HTML specifications.
In the next step, we can add an HTML body. This time we’ll skip the merge field and concentrate on testing the HTML content.
Then we need to configure the text version of the email. That way, the body text of the email will still be visible even if the email client doesn’t render the HTML properly. Click Save.
You will see the preview of the email. Let’s send it as we did before and inspect it in our virtual inbox.
2. Then let’s move to the HTML Source tab. There, you’ll see all the problematic elements marked with a red exclamation icon.
3. Go to the HTML check tab to inspect client support in more detail. Here, you can filter results by a specific client/device or view the overall HTML support percentage. Check out our knowledge base article to learn how HTML check works and how to interpret data.
After analyzing the HTML check results, you can adjust the code and correct/remove elements that might stop your Salesforce emails from rendering in your contacts’ inboxes.
With Mailtrap, you can test any type of Salesforce email alert. The following sections detail all the steps, but we’ll start by creating an alert first.
2. Fill out the fields based on the your testing needs and click the “Save” button. Keep in mind that the fields labeled red are mandatory. Also, we used exemplary object and email template, so you may need to change that based on your testing needs.
An Email Alert can be sent via Workflow Rules, Process Builder, and the Flow.
Here are the steps for each method.
2. Select the Contact object.
3. Under Evaluation Criteria, choose “created, and every time it’s aded”. Then, at Rule Criteria choose Contact Email under Fields, Operator “not equal to”, and the “null” Value. Lastly, click the Save&Next button.
4. Thereon, click the “Add Workflow Action” button and select Existing Action.
5. Choose the Email Alert which you previously created and click the ”Save” button.
6. Go to the Workflow Rules one more time and activate the process.
2. Go to Mailtrap and make sure that the email is delivered.
2. Fill out the fields based on your testing needs, and click the “Save” button.
Tip: Make the Process and API name and the Description congruent for easier reference. Keep the variable under “The process starts when” at “A record changes”.
3. Choose the Contact object and in “Start the process” field select “only when a record is created” option, then click the “Save” button.
4. Add Criteria based on your testing needs – we built the Process based on the example used in this article.
5. Click the IMMEDIATE_ACTIONS tile, and under the “Action Type” choose Email Alerts, then select the Email Alert created in the previous steps, and click the “Save” button.
6. Activate Process builder.
Tip: If you want to get email only from Process Builder, deactivate Workflow rules before creating a new contact. Otherwise, will be executed Workflow rule too because this rule also meet the criteria.
2. Go to Mailtrap and make sure that the email is delivered.
2. Select Record-Triggered Flow and click the “Create” button.
3. Configure Start as per your testing needs and click the “Done” button. Note that you should keep the Configure Trigger option at “A record is created or updated”.
4. Click the white dot to add a new element.
5. Under Shortcuts choose “Sent Email Alert”.
6. Fill out the fields to label and describe the action, then hit the “Done” button.
7. Save the Flow
8. Activate the Flow
Tip: If you want to get email only from Flow, deactivate Workflow rules and Process Builder before creating a new contact. Otherwise, will be executed Workflow rule and Process Builder too because these rule also meet the criteria.
2. Go to Mailtrap and make sure that the email is delivered.
With the help of Mailtrap Email Testing, you can test bulk email handling in Salesforce. This test will validate the Apex limits and check if your bulk emails are getting delivered properly.
Just like with previous tests, Email Testing’s SMTP credentials should be set up as an email relay.
The first step is to create a sufficient amount of contact data by importing data with a Data Import Wizard or adding a couple of sample contacts manually. For the latter, press on the application icon and choose Marketing.
Under the Contacts tab, click New. Enter the name of the contact, create a new account to associate with the contact, and enter the email address. Save the settings and repeat the process for any other contact you want to add.
Once you’re done, your contacts list should look something like this:
Next, create a sample template, open it and note the template’s ID. It’s located in the URL and starts with 00X.
At this point, we can start writing an Apex Class.
Add a new class in Apex classes with the following script:
This piece of code requires contact IDs. So, to run the script, we should ask Apex to grab contact IDs first and then send an email. Open the developer console and in the Open Execute Anonymous Window, add the following lines:
Press Execute. In a few seconds, the emails will pop up in your Mailtrap virtual inbox indicating that your Salesforce platform can successfully send bulk emails.
Note: The code piece above will send an email to 50 contacts by default. You should update your SOQL query if you need to send more. Also, depending on the type of your Salesforce org and the package you’re using, your daily email sending volume may also be limited.
This wraps up our tutorial on testing emails in Salesforce with Mailtrap Email Testing. Now you can successfully inspect and debug email deliverability, text and HTML templates, and bulk email handling.
Don’t forget to organize your virtual inbox by creating different projects and inboxes. That will simplify the testing process and keep your data in one place.
To learn more about Mailtrap, click here.
Thanks for reading our guide on testing emails in Salesforce with Mailtrap! You can find the original piece on our blog.
Join other developers and claim your FAUN account now!
Influence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.