Geeks logo

How to Test Emails in Salesforce with Mailtrap Email Testing

Ensure Seamless Communication: Mastering Email Testing in Salesforce using Mailtrap

By Sofia TarhonskaPublished 11 months ago 4 min read
Like

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.

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.

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 bulk email handling

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:

public class BulkEmailHandler {

public static void sendBulkEmail(List<Id> contactIds) {

Messaging.reserveMassEmailCapacity(contactIds.size());

Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();

mail.setTargetObjectIds(contactIds);

mail.setTemplateId('your_template_id'); // replace 'your_template_id' with the actual ID of your email template

mail.setSaveAsActivity(false);

Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

}

}

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:

List<Contact> contacts = [SELECT Id FROM Contact LIMIT 10];

List<Id> contactIds = new List<Id>();

for (Contact c : contacts) {

contactIds.add(c.Id);

}

BulkEmailHandler.sendBulkEmail(contactIds);

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.

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

how to
Like

About the Creator

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

Sofia Tarhonska is not accepting comments at the moment

Want to show your support? Send them a one-off tip.

Find us on social media

Miscellaneous links

  • Explore
  • Contact
  • Privacy Policy
  • Terms of Use
  • Support

© 2024 Creatd, Inc. All Rights Reserved.