cover-img

How to Test Emails in Salesforce with Mailtrap Email Testing

16 June, 2023

0

0

0

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.

What is Mailtrap Email Testing?

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

  • A fake SMTP server to eliminate the risk of spamming users;
  • HTML analysis to check how your emails will render in different email clients;
  • Spam analysis for popular spam filters and blacklists;
  • SMTP and API for easy integration;
  • Ready-made code snippets for popular languages and frameworks;
  • Multiple inboxes for different projects and stages.

Try Email Testing for Free

When should you use Mailtrap Email Testing?

There are several use cases where you should opt for Mailtrap Email Testing. Let’s quickly discuss each of them below.

Avoiding spamming users with test emails

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.

Testing email format and content

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.

Try Email Testing for Free

Keeping all test emails in one place

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.

How to test email deliverability

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).

  1. Go to Mailtrap’s sign up page and choose the desired method of registration;

  1. 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.

  1. Click on your inbox and hit Show Credentials to reveal the credentials for the fake SMTP server.

  1. Go to your Salesforce account and navigate to Setup → Email (under Administration) → Email Relays.

  1. Click Create Email Relay and fill out the form with Email Testing’s SMTP credentials as in the example below:

  1. Click Enable SMTP Auth to connect to the SMTP server with authentication. Enter your SMTP username and password.

  1. Click Save. Head to Email Domain Filters and click Create Email Domain Filter. This step is necessary to activate the relay.

  1. 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.

public class SendSingleEmail {
public void sendSingleEmailMethod(){

Messaging.reserveSingleEmailCapacity(2);
Messaging.SingleEmailMessage mymail = new Messaging.SingleEmailMessage();

// Ensure that addresses are correctly formatted and matching case
String[] toAddresses = new String[] {'recipient@example.com'};

mymail.setToAddresses(toAddresses);
mymail.setReplyTo('no-reply@example.com');
mymail.setSenderDisplayName('Salesforce Support');
mymail.setSubject('Test Email ');
mymail.setPlainTextBody('This is the first test email sent from Salesforce with Mailtrap Email Testing');
mymail.setHtmlBody('<p>This is the first test email sent from Salesforce with Mailtrap Email Testing</p>');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mymail });
}
}

Copy

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.

sendSingleEmail obj = new sendSingleEmail();
obj.sendSingleEmailMethod();

Copy

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.


Thank you for reading a part of our guide on Mailtrap Salesforce integration! If you'd like to discover more about it, feel free to check out the Mailtrap Blog. ;)

0

0

0

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.