<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Veljko Ristic</title>
    <description>The latest articles on Forem by Veljko Ristic (@veljkoristic).</description>
    <link>https://forem.com/veljkoristic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1189340%2F7b6b2364-c7f0-46d7-98ce-1ca0b1330b62.jpeg</url>
      <title>Forem: Veljko Ristic</title>
      <link>https://forem.com/veljkoristic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/veljkoristic"/>
    <language>en</language>
    <item>
      <title>How to Set Up, Configure, and Send Emails using Yahoo SMTP Server</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Wed, 23 Oct 2024 12:08:05 +0000</pubDate>
      <link>https://forem.com/veljkoristic/how-to-set-up-configure-and-send-emails-using-yahoo-smtp-server-4aod</link>
      <guid>https://forem.com/veljkoristic/how-to-set-up-configure-and-send-emails-using-yahoo-smtp-server-4aod</guid>
      <description>&lt;p&gt;No reason to beat around the bush. As the title suggests, I guide you through everything you need to know about Yahoo SMTP. &lt;/p&gt;

&lt;p&gt;Let’s get straight to it. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Yahoo SMTP?
&lt;/h2&gt;

&lt;p&gt;SMTP, or &lt;a href="https://mailtrap.io/blog/smtp/" rel="noopener noreferrer"&gt;Simple Mail Transfer Protocol&lt;/a&gt;, is a mail server protocol for sending emails over the Internet. Yahoo SMTP allows users to send emails from their Yahoo Mail account through other email clients like Microsoft Outlook, Mozilla Thunderbird, or any other standard email application that supports SMTP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F019jyykywfwzx8knp1kq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F019jyykywfwzx8knp1kq.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the technical side, here are the Yahoo SMTP settings to keep at hand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SMTP server address&lt;/strong&gt;: smtp.mail.yahoo.com&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ports&lt;/strong&gt;: Either 465 (with SSL) or 587 (with TLS), depending on your email client’s capabilities and security preferences.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encryption&lt;/strong&gt;: SSL or TLS based on the port you choose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Necessary. Use your full email address and an app-generated password. This goes double if you have 2FA enabled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I’ll explain the app-generated password and all the setup flows in a later section. If you want to jump to it, click here. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why should you use Yahoo as an SMTP server?
&lt;/h2&gt;

&lt;p&gt;Assuming you’ll use this email server for a pet project, personal use, or just to see how Yahoo Mail SMTP works, there are a few reasons to do it. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Wide compatibility&lt;/strong&gt;: Yahoo SMTP is compatible with a broad range of email clients, making it easy to integrate into almost any system without special configuration. (You’ll see it soon, it’s often just a few clicks to have the outgoing mail and incoming mail up and running.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High deliverability&lt;/strong&gt;: Yahoo has robust systems in place to ensure high deliverability rates for your emails, minimizing the risk of them being marked as spam. (Keep in mind that deliverability isn’t only on the email service side, it has a lot to do with the type of outgoing emails you send.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Account security&lt;/strong&gt;: Yahoo supports secure connections via SSL/TLS, helping protect your data from interception during transmission.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No cost for personal use&lt;/strong&gt;: Yahoo provides SMTP services at no additional cost, which is beneficial for individuals or small businesses looking to minimize expenses. But the email provider does impose certain (I’d say stringent) limitations. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reliability&lt;/strong&gt;: Yahoo is a long-established company with a reputation for reliable service. Using their SMTP server can lend credibility and stability to your email communications. Still, you shouldn’t be surprised if an occasional email lands in tabs or the spam folder with Outlook or Gmail. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simple setup&lt;/strong&gt;: This is probably the biggest plus for me. Setting up Yahoo SMTP is straightforward, with clear documentation and support available, making it accessible even for those with minimal technical expertise.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to configure Yahoo SMTP server settings?
&lt;/h2&gt;

&lt;p&gt;I’ll start with creating the in-app password, then move to show you the email settings with Thunderbird. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step #1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a dedicated app password, you can’t use the password you have for the Yahoo account. Do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to your Yahoo account (&lt;strong&gt;Note&lt;/strong&gt;: Not the mail account but your general account info on Yahoo)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fknj0pfzj43bw867ejs7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fknj0pfzj43bw867ejs7c.png" alt="Image description" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select the Security tab, scroll down, and choose “Generate app password” under ‘App Password’ section. This generates a special SMTP password you can use for third-party integrations. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90r2rnyyakxz7hm1r6h8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90r2rnyyakxz7hm1r6h8.png" alt="Image description" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Follow the wizard, enter the app name, and confirm with the “Generate password” button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4atxehf8m7rjk6igck16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4atxehf8m7rjk6igck16.png" alt="Image description" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The system will show you the password; copy-paste it somewhere safe for future reference.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step #2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, access the email client you’d like to use and add the SMTP settings. For the purposes of this tutorial, I’ll use Thunderbird. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In Thunderbird, click the Gear icon at the lower left corner, then choose Account Settings. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbaa4j39j1qayt10atmju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbaa4j39j1qayt10atmju.png" alt="Image description" width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click the “Account Actions” menu at the bottom left, then select “Add Mail Account” to add Yahoo SMTP. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbpmiop9lss4mlrjr127.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbpmiop9lss4mlrjr127.png" alt="Image description" width="558" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Type your Yahoo SMTP credentials into the designated fields. Make sure to use the app password you previously created, and hit Continue. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0skf7ecp53gtq5kl37qb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0skf7ecp53gtq5kl37qb.png" alt="Image description" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The wizard takes you to the Yahoo popup where you need to complete the authentication via login and 2FA. Proceed with it; once done, your account will immediately pop up in Thunderbird.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nriy6rt5j1lh34xjhj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nriy6rt5j1lh34xjhj6.png" alt="Image description" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Notes&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thunderbird allows you to automatically set up POP (Post Office Protocol) and IMAP (Internet Message Access Protocol), the later being selected by default. Feel free to proceed with that configuration, there’s no reason to do it manually with this client. But for the sake of this tutorial, I’ll show you the manual setup in the coming sections. &lt;/li&gt;
&lt;li&gt;Thunderbird bakes in the POP3 or IMAP settings (‘ON’ by default). You can update some of the credentials, however, there’s no option for manual setup after you add the SMTP. You’d need to re-add the SMTP and then choose “Manual setup”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4tverqg4mpgv2y7138c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff4tverqg4mpgv2y7138c.png" alt="Image description" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to configure Yahoo POP3 settings?
&lt;/h2&gt;

&lt;p&gt;Here I’ll show you the manual setup that may generally apply to other clients. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the account settings or preferences within your email client. This is typically found in the ‘Accounts’ or ‘Email’ settings section.&lt;/li&gt;
&lt;li&gt;Choose the option to add a new email account, and select ‘Manual setup’ or ‘Additional server types’ when prompted.&lt;/li&gt;
&lt;li&gt;When asked for the account type, select POP settings or POP3.&lt;/li&gt;
&lt;li&gt;Enter POP3 server details and your credentials:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;POP3 server (Host)&lt;/strong&gt;: pop.mail.yahoo.com&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: 995.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encryption&lt;/strong&gt;: Ensure SSL/TLS encryption is enabled for securing your email data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Required. Enter your full Yahoo email address and the app password.
(Reminder: this is the Yahoo mail password you generated, not the Yahoo account password)&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;[Optional] – Some clients may have the “Leave a copy of messages on the server” option. You can check it if you want the email backup. &lt;/li&gt;
&lt;li&gt;Save the settings. Depending on the client, the ‘Test Account Settings’ button could be available. This will send a test message to verify the setup. But with more recent client updates, there’s just a confirmation notification.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to configure Yahoo IMAP settings?
&lt;/h2&gt;

&lt;p&gt;The manual configuration for IMAP is almost the same as for POP3, so I won’t be repeating all the steps. Basically, you add a new account, select ‘Manual setup’ or ‘Additional server types’, and move on to add the following credentials. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMAP server (Host)&lt;/strong&gt;: imap.mail.yahoo.com&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Port&lt;/strong&gt;: 993&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encryption&lt;/strong&gt;: SSL/TLS enabled. This setting secures the data transmission between your email client and Yahoo’s servers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;: Required. Use your full Yahoo email address and the in-app password you created.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IMLFrYqI-oQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting Yahoo SMTP server configuration
&lt;/h2&gt;

&lt;p&gt;I collected a list of frustrating little errors that may block the server and tips on how to fix them. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Authentication errors&lt;/strong&gt; – typically occur because of the wrong settings or login credentials. To avoid them, double-check your username and password. Also, as a reminder, you need to use the app password you create, particularly if you have the 2FA ON. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;“Server not responding” or the “Connection timed out”&lt;/strong&gt; – the errors could appear due to network/internet connection issues, incorrect SMTP settings, or server downtime. The only thing you can do is check that the SMTP server address (smtp.mail.yahoo.com) and port numbers (465 with SSL or 587 with TLS) are correct. If it’s server-side, you can only wait and try again later. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL/TLS errors&lt;/strong&gt; – these are rare but may occur if the email client doesn’t support the encryption method you chose. You can check if the SSL/TLS is enabled and if you’re on the correct ports – 465 for SSL and 587 for TLS. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;“Email sending limit exceeded”&lt;/strong&gt; – this happens when you send more emails than you’re allowed to. To offset the limitation, try to reduce the sending frequency. That may help since Yahoo times you out of the service whenever you hit the threshold. But it’s also a signal you should be looking for a different service. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firewall or ISP blocks&lt;/strong&gt; – Sometimes certain network configurations or ISPs block SMTP ports used by Yahoo (again, this isn’t common for most IPSs). If it happens, reach out to the ISP to see if they block SMTP ports 465 or 587 (the former is more likely to be blocked). In this case, you may need to use a different port. And if it’s your firewall, you’ll need to reconfigure it to allow Yahoo SMTP.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Yahoo SMTP limitations: when not to use Yahoo as a SMTP server
&lt;/h2&gt;

&lt;p&gt;Interestingly, in an attempt to discourage spammers, &lt;a href="https://help.yahoo.com/kb/SLN3353.html" rel="noopener noreferrer"&gt;Yahoo chooses not to disclose&lt;/a&gt; its limitations publicly. But I did some digging, since I didn’t run the testing myself, and came up with a few consistent numbers that make sense. &lt;/p&gt;

&lt;p&gt;Based on the &lt;a href="https://woodpecker.co/blog/email-sending-limits/" rel="noopener noreferrer"&gt;Woodpecker blog&lt;/a&gt; and a few other resources, you can send up to 500 emails per day, and a single email can be sent to 100 recipients max. Also, it’s speculated that the hourly throughput caps at 100 emails. &lt;/p&gt;

&lt;p&gt;More importantly, &lt;a href="https://mailtrap.io/blog/gmail-yahoo-email-sender-requirements/" rel="noopener noreferrer"&gt;Yahoo updated its sender requirements&lt;/a&gt; not that long ago, making domain authentication via DNS records one of the main requirements for bulk senders. Check the video below where we discuss the update in detail. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IOl_FOcOSk0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now, I’d always say you need to authenticate your domain via DNS, regardless of the SMTP provider. However, the limitation of 500 emails a day may only be suitable for solopreneur startups and tiny businesses. &lt;/p&gt;

&lt;p&gt;But even if you choose to go the Yahoo route, imagine what happens if you get a surge of customers or queries and you need to scale fast. Simply, you’ll be blocked for a while, potentially losing customers. &lt;/p&gt;

&lt;p&gt;Finally, Yahoo doesn’t offer advanced analytics and segmentation, A/B testing, and a bunch of other features that are likely to make your campaigns more efficient. So it pays to explore alternatives. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a reliable alternative to Yahoo SMTP?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://mailtrap.io/email-sending/" rel="noopener noreferrer"&gt;Mailtrap Email API/SMTP&lt;/a&gt; is a reliable alternative to Yahoo SMTP. It’s part of the Mailtrap Email Delivery Platform that allows you to test, send, and control your email infrastructure in one place. &lt;/p&gt;

&lt;p&gt;Hit play to see it in action.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vAfUyKpWj_M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;More importantly, Mailtrap allows you to scale with ease and have access to all the advanced tools that help make your campaigns and email sending more effective. &lt;/p&gt;

&lt;p&gt;Okay, I’ve been there to see Mailtrap grow to the platform that it is today, so I could be subjective. But let me break down the features for you to help you make an informed decision. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;In-depth analytics&lt;/strong&gt;: You get a helicopter-view dashboard to assess the email performance at a glance. And there are drill-down reports where you can check the deliverability for different mailbox providers, email categories, and more. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyak1qpoieaaxv807638w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyak1qpoieaaxv807638w.png" alt="Image description" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;24/7 human support&lt;/strong&gt;: Yes, there are real people to address your support tickets quickly. Plus, we have deliverability experts who can assist with any technical challenge you may encounter. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure setup&lt;/strong&gt;: All the DNS records are provided for you, and there’s an option to send setup instructions to a team member. And Mailtrap supports SSL and TLS. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasxb78klb3ptex4q36z9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasxb78klb3ptex4q36z9.png" alt="Image description" width="800" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SMTP and API&lt;/strong&gt;: Even if you’re on a free plan, you get access to RESTful APIs and SDKs in major languages. This may be invaluable if you’re a dev and want to automate email-sending processes within your app or service. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email templates&lt;/strong&gt;: There’s a drag-and-drop interface to create visually appealing templates and accessible templates. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fud5r67livedz32fsklg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fud5r67livedz32fsklg1.png" alt="Image description" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dedicated IPs&lt;/strong&gt;: If you send more than 100K emails a month, you can get a dedicated IP for greater control over your deliverability and sender reputation. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email testing&lt;/strong&gt;: Mailtrap email testing provides a fully-featured sandbox solution to check your emails without spamming real recipients.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this gives you enough of a reason to give Mailtrap a try, so go on and hit the button below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://mailtrap.io/register/signup?ref=header" rel="noopener noreferrer"&gt;Try Mailtrap Email API/SMTP Now&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;When all is said and done, Yahoo SMTP is an okay solution to get your feet wet with SMTP services. It’s super easy to set up, many of the processes have been automated, and email-sending is straightforward regardless of the client or app you use. &lt;/p&gt;

&lt;p&gt;However, if you’re down for business, you’ll need to choose an SMTP provider with more features and much less limitations. Hopefully, it’ll be Mailtrap 😀.&lt;/p&gt;

&lt;p&gt;We appreciate you chose this article to know about Yahoo SMTP. To read more articles on the related topics, visit &lt;a href="https://mailtrap.io/blog/yahoo-smtp/" rel="noopener noreferrer"&gt;Mailtrap blog&lt;/a&gt;! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting up GoDaddy SMTP to Send Emails</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Mon, 21 Oct 2024 12:56:27 +0000</pubDate>
      <link>https://forem.com/veljkoristic/setting-up-godaddy-smtp-to-send-emails-2b7i</link>
      <guid>https://forem.com/veljkoristic/setting-up-godaddy-smtp-to-send-emails-2b7i</guid>
      <description>&lt;p&gt;When you think of an SMTP email server, GoDaddy isn’t the first thing that comes to mind. But the hosting behemoth gives you a few options to set it up, even if you want to use a third-party provider. &lt;/p&gt;

&lt;p&gt;Here, I cover everything about GoDaddy SMTP, from options to &lt;a href="https://mailtrap.io/blog/godaddy-smtp/#use" rel="noopener noreferrer"&gt;use cases&lt;/a&gt; and &lt;a href="https://mailtrap.io/blog/godaddy-smtp/#configure" rel="noopener noreferrer"&gt;detailed integrations&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Hop on to make the emails fly from your website or ecommerce. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a GoDaddy SMTP server?
&lt;/h2&gt;

&lt;p&gt;GoDaddy SMTP is an SMTP relay that allows you to set up email sending and custom addresses from your domain. There are also email and calendar sharing options, as well as integrations with third-party email clients. &lt;/p&gt;

&lt;p&gt;Note that the outgoing server isn’t enabled by default and it’s a paid feature (the basic email is just like a limited free trial), and the paid options are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Individual&lt;/strong&gt; – you get a domain-based email and 10GB of storage. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team&lt;/strong&gt; – for team collabs; you get 30GB + sharing options. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft 365 Email Essentials&lt;/strong&gt; – Microsoft backend + 10 GB of storage + compatibility with Apple Mail and Microsoft Outlook. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft 365 Online Business Essentials&lt;/strong&gt; – 50 GB of storage + Microsoft web apps + collaboration options. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I haven’t covered any pricing since it’s hard to pinpoint the exact number because GoDaddy has rolling discounts and marked differences depending on whether you want to pay monthly or yearly. You can &lt;a href="https://www.godaddy.com/en-ph/email" rel="noopener noreferrer"&gt;check the pricing here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;As for the actual SMTP server details, here’s what they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SMTP server address&lt;/strong&gt;: smtpout.secureserver.net&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: 465 (SSL) / 587 (TLS)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Required&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Username&lt;/strong&gt;: Your full email address&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password&lt;/strong&gt;: The account password you use for the email address&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important Note&lt;/strong&gt;: &lt;a href="https://www.reddit.com/r/email/comments/18xngqm/does_godaddy_prevent_using_external_smtp_servers/" rel="noopener noreferrer"&gt;Users report&lt;/a&gt; that GoDaddy blocks direct routing to an external SMTP server on all hosting plans, meaning you can only use their servers or Microsoft. The good news is that this isn’t entirely true and there are two ways around the block.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can set up an external SMTP email provider and have full control over your email sending on GoDaddy VPS hosting plans. (Suggestion: reach out to GoDaddy support for more info on how to migrate from a different plan)&lt;/li&gt;
&lt;li&gt;There’s an option to run the email setup via cPanel, but it’s tricky to validate your domain name and handle spam.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tips&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose port number 587, especially if you’re setting up the SMTP for a WordPress website, the 465 alternative could be blocked. &lt;/li&gt;
&lt;li&gt;Don’t just copy-paste the SMTP server details into your email client or site, there are steps before that, check the “&lt;a href="https://mailtrap.io/blog/godaddy-smtp/#configure" rel="noopener noreferrer"&gt;How to configure…&lt;/a&gt;” section below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why should you use GoDaddy SMTP server?
&lt;/h2&gt;

&lt;p&gt;If I were to be laconic, I’d say use GoDaddy because it’s convenient, but let’s break down the reasons in more detail:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You’re hosting with GoDaddy&lt;/strong&gt; – for existing users, GoDaddy allows for a simple way to send professional emails using your custom domain (e.g. &lt;a href="mailto:email@yourdomain.com"&gt;email@yourdomain.com&lt;/a&gt;). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of use&lt;/strong&gt; – Setting up GoDaddy SMTP is a click-and-copy-paste job, making the whole process straightforward even if you’re not tech-savvy. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reliable delivery&lt;/strong&gt; – The hosting provider uses authentication protocols to ensure emails are delivered securely and with minimal risk of being flagged as spam. (This goes assuming your domain hasn’t been compromised in any way.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Keep in mind that there are &lt;a href="https://mailtrap.io/blog/godaddy-smtp/#limitations" rel="noopener noreferrer"&gt;certain limitations&lt;/a&gt; that may make GoDaddy webmail a lesser choice, particularly if you want to send email campaigns. ↖️Click the link to learn more. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to configure GoDaddy SMTP server settings?
&lt;/h2&gt;

&lt;p&gt;For the configuration steps, I’m assuming you already have a domain set up with GoDaddy but haven’t configured email settings yet. The whole process takes a few steps, and I’ll also show you how to integrate the SMTP server with Thunderbird. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 – Enable email sending&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log into your GoDaddy account, click the account name, and select “My Products”. 
GoDaddy account dropdown&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nzw0x3m0l59eum5hgq9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nzw0x3m0l59eum5hgq9.png" alt="Image description" width="750" height="952"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scroll down, then click “Set up an email account” under the domain you want to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frad9ye0zjhbrjq8rewdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frad9ye0zjhbrjq8rewdg.png" alt="Image description" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick tips&lt;/strong&gt;: If the “Set up” button is declicked, click it to reveal the options. There’s also an alternative route: Click “Manage”, and then “Email” at the menu on the left. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcv6zon3ori4un461dl1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcv6zon3ori4un461dl1.png" alt="Image description" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose the option that best suits your needs (Individual or Team), and follow the GoDaddy wizard to add the service. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Set up your email with GoDaddy&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the email feature enabled, go back to “My Products”, scroll down, and open the “Email &amp;amp; Office” menu. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50qld3pvzgkqf6aoiz61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50qld3pvzgkqf6aoiz61.png" alt="Image description" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the “Set up” button to proceed, and choose the domain you’d like to use (this goes assuming you have multiple domains). Then hit “Continue”. &lt;/li&gt;
&lt;li&gt;Fill out the form and make sure to add an alternative email address. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipobtv21k22tc5bb2voe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipobtv21k22tc5bb2voe.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the “Create” button, then log into your newly created email account to ensure everything’s working as it should. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Important&lt;/strong&gt;: You need to turn on Authentication to enable GoDaddy’s SMTP. Under “Email &amp;amp; Office” select “Manage all” and navigate to your email address. Then, click the “Manage” button. &lt;/li&gt;
&lt;li&gt;Scroll down to the “Account Information” section and click “Advanced settings”. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F225b0wu42byzwh2uurwl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F225b0wu42byzwh2uurwl.png" alt="Image description" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The action reveals the corresponding menu, where you need to make sure “SMTP Authentication” is toggled on. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw3fzedli3827mj0uvma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw3fzedli3827mj0uvma.png" alt="Image description" width="652" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Integrate GoDaddy SMTP with your email client&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As mentioned, I’ll be Thunderbird, but the setup logic is the same for other clients, though the naming and routes could be different. Anyway, here are the SMTP settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launch Thunderbird, hit the gear icon to access “Settings”, and select “Account Settings”. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrt95mkcvpx7pjsbjc31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrt95mkcvpx7pjsbjc31.png" alt="Image description" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the “Account Settings” menu, click “Account Actions” and choose “Add Mail Account”. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbzdj3jyk1m232tv52zc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjbzdj3jyk1m232tv52zc.png" alt="Image description" width="510" height="548"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type your email credentials (the credentials for the custom email you created in the previous steps), then hit Continue. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You should be able to use the account almost immediately, but there could be intermediary authentication steps. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F763gd0p1s6f66j1hzhrh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F763gd0p1s6f66j1hzhrh.png" alt="Image description" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With Thunderbird IMAP is configured automatically based on the credentials you provided. But if you need to change the settings, click “Configure manually” and update them. (In most cases, this is a redundant step). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F507j1pvfsj8snr0estsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F507j1pvfsj8snr0estsb.png" alt="Image description" width="800" height="1004"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus Step: Integrate GoDaddy SMTP with WordPress plugin&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The case is: you’re hosting with GoDaddy and want to send emails from your website but avoid the notoriously unreliable native ‘wp_mail()’ function. I already blogged extensively on how to do this and you can &lt;a href="https://mailtrap.io/blog/wordpress-send-email/#How-to-send-emails-using-the-WordPress-SMTP-plugin" rel="noopener noreferrer"&gt;check the full tutorial here&lt;/a&gt;. Now, I just want to give you the digest flow, for more details hit the link ⬆️. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the WP Mail SMTP plugin and activate it.&lt;/li&gt;
&lt;li&gt;Launch the plugin, navigate to “Settings”, then scroll down to the “Mailer” section.&lt;/li&gt;
&lt;li&gt;Choose “Other SMTP” and enter &lt;a href="https://mailtrap.io/blog/godaddy-smtp/#credentials" rel="noopener noreferrer"&gt;GoDaddy SMTP credentials&lt;/a&gt; as listed earlier. &lt;/li&gt;
&lt;li&gt;Make sure to enter the proper username and password for your GoDaddy account. &lt;/li&gt;
&lt;li&gt;Send a test email to confirm the configuration is working.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Reminder&lt;/strong&gt;: While this is a convenient way and you don’t need to get a dedicated SMTP service, there are still GoDaddy SMTP limitations. So, if you, for example, want to send full-on email campaigns, &lt;a href="https://mailtrap.io/blog/godaddy-smtp/#alternative" rel="noopener noreferrer"&gt;it’s actually worth considering an alternative&lt;/a&gt;. &lt;/p&gt;
&lt;h2&gt;
  
  
  How to configure GoDaddy POP3 settings?
&lt;/h2&gt;

&lt;p&gt;Depending on the type of setup you choose, POP3 or IMAP settings may be enabled by default. I’ll cover the technical details and a general setup flow for various clients and/or integrations via a WordPress plugin. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical details&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;POP server address&lt;/strong&gt;: pop.secureserver.net&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: 995 (SSL required)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Username&lt;/strong&gt;: Your GoDaddy email address&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password&lt;/strong&gt;: The password for your email account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;General setup flow&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your email client and head to the “&lt;em&gt;Incoming Mail Server&lt;/em&gt;” settings. Depending on the client the naming could be different; e.g. &lt;em&gt;Add Server&lt;/em&gt;, &lt;em&gt;Incoming Server Settings&lt;/em&gt;, etc. &lt;/li&gt;
&lt;li&gt;Choose POP3 as the protocol.&lt;/li&gt;
&lt;li&gt;Enter the POP3 details for the server address, port, username, and password.&lt;/li&gt;
&lt;li&gt;Save the changes and test the incoming mail functionality.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  How to configure Godaddy IMAP settings?
&lt;/h2&gt;

&lt;p&gt;As shown earlier, Thunderbird lets you select and integrate IMAP automatically, and you’ll encounter a similar flow with most contemporary clients. But if you need to do it manually (e.g. with a WordPress plugin), check the technical details below. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I won’t include the general setup flow here since it’s not necessary, it’s exactly the same as for POP3. And the protocols are typically one above the other in email clients and WordPress SMTP plugins menus. Therefore, there’s almost no chance of getting lost. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical details&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;IMAP server address&lt;/strong&gt;: imap.secureserver.net &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port&lt;/strong&gt;: 993 (SSL required)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Username&lt;/strong&gt;: Your GoDaddy email address&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password&lt;/strong&gt;: The password for your email account&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Troubleshooting GoDaddy SMTP server configuration
&lt;/h2&gt;

&lt;p&gt;Honestly, the issues with GoDaddy SMTP setup are few and far between. But just in case, check some problems that you might encounter. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Incorrect username or password&lt;/strong&gt;: Double-check that you’re using the correct GoDaddy email credentials. These are the same credentials as for your GoDaddy account. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port not working&lt;/strong&gt;: Make sure you’re using the correct port (465 for SSL or 587 for TLS). If one port doesn’t work, try the other. As mentioned earlier, it would be better to try the 587 port first. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Firewall or ISP blocking SMTP&lt;/strong&gt;: Your internal firewall and some ISPs block certain ports for security reasons. With popular ISPs this shouldn’t be too much of a problem, but the firewall could be the likely culprit. If so, whitelist or allow the SMTP in the firewall settings and restart the service. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SMTP Authentication not enabled&lt;/strong&gt;: Verify that SMTP Authentication is turned on in your email client settings. To stress, you literally have to toggle on the Authentication as shown in the “How to configure…” section.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  GoDaddy SMTP limitations or when not to use GoDaddy as a SMTP server
&lt;/h2&gt;

&lt;p&gt;Here are the limitations to consider when choosing GoDaddy: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Email sending limits&lt;/strong&gt;: GoDaddy imposes a daily sending limit (often 250 emails per day for standard accounts, and &lt;a href="https://www.godaddy.com/en-in/help/professional-email-account-limitations-31970" rel="noopener noreferrer"&gt;500 emails via SMTP for Professional Email accounts&lt;/a&gt;). As indicated, this can be restrictive if you’re running email campaigns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;External SMTP server routing&lt;/strong&gt;: As a reminder, you need a GoDaddy VPS hosting plan to set up an external SMTP server smoothly. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No advanced email analytics&lt;/strong&gt;: GoDaddy’s SMTP server is mainly for basic email sending. If you need detailed email tracking, you might want to explore third-party options&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lack of email template support&lt;/strong&gt;: GoDaddy does not offer built-in support for advanced email templates, making it less ideal for marketing emails.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Consider an alternative – using Mailtrap SMTP Service
&lt;/h2&gt;

&lt;p&gt;Want to send more emails per day? Need detailed analytics to keep tabs on the performance of your emails? Then, M&lt;a href="https://mailtrap.io/email-sending/" rel="noopener noreferrer"&gt;ailtrap Email API/SMTP&lt;/a&gt; is the service that ticks all the right boxes.&lt;/p&gt;

&lt;p&gt;Why? &lt;/p&gt;

&lt;p&gt;The Email API/SMTP is part of Mailtrap Email Delivery Platform that allow you to test, send, and control your emails. As such it’s a great solution for dev and marketing teams. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vAfUyKpWj_M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can send as many emails a day as you need with flexible throughput limitations. Of course, this goes assuming your domain is healthy and the templates aren’t spammy. And you get email delivery stats that are hard to rival.  &lt;/p&gt;

&lt;p&gt;But, I’d like to dive a bit deeper into the features and show you all that’s worth your attention. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: You are provided with all the DNS records, you can copy-paste to your GoDaddy domain management. Plus, Mailtrap supports SSL and TLS. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human support 24/7&lt;/strong&gt;: We employ a team of experts who can address all your needs in a matter of hours. Also, there’s a dedicated delivery expert to assist you if you migrate to Mailtrap, for example.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In-depth analytics&lt;/strong&gt;: A quick glance at Mailtrap’s helicopter-view dashboard allows you to check your stats on the fly. But there are quick-access drill-down reports across different verticals like email categories, mailbox providers, opens, clicks, etc. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email templates&lt;/strong&gt;: You get a drag-and-drop visual template builder. You can add merge fields using Handlebars, and it’s easy to switch to HTML editing. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SMTP and API&lt;/strong&gt;: Besides SMTP, you get access to RESTful API and Mailtrap SDKs, even on a free plan. This helps you scale email sending and set up automation as your website, product or service grows. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Email testing&lt;/strong&gt;: This is a &lt;a href="https://mailtrap.io/email-sandbox/" rel="noopener noreferrer"&gt;sandbox solution&lt;/a&gt; to test your emails without spamming recipients. It helps debug the templates fast before moving them to production. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dedicated IP&lt;/strong&gt;: If you need to send more than 100,000 emails per month, you can get a dedicated IP to gain more control over your email infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;All in all, GoDaddy SMTP is a good solution if you host your websites with them, but the use cases are limited. If you’re a small business or online service with a handful of customers, it may work well. &lt;/p&gt;

&lt;p&gt;However, it’s still a paid feature, so it might be better to opt for a third-party provider that allows you to scale properly and have usable analytics. Guess what provider I’d recommend 😀 &lt;/p&gt;

&lt;p&gt;We appreciate you chose this article to know hoe to set up GoDaddy SMTP for email sending. To read more interesting articles on related topics, follow &lt;a href="https://mailtrap.io/blog/godaddy-smtp/" rel="noopener noreferrer"&gt;Mailtrap Blog&lt;/a&gt;!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Validate Emails in PHP: regex, filter_var(), and API Explained</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Tue, 14 May 2024 11:14:33 +0000</pubDate>
      <link>https://forem.com/veljkoristic/how-to-validate-emails-in-php-regex-filtervar-and-api-explained-4h57</link>
      <guid>https://forem.com/veljkoristic/how-to-validate-emails-in-php-regex-filtervar-and-api-explained-4h57</guid>
      <description>&lt;p&gt;Be it marketing or transactional emails, email address validation is a necessity, or you could risk the reputation of your email domain. &lt;/p&gt;

&lt;p&gt;This tutorial covers the ins and outs of PHP email validation and is primarily designed for beginners. However, I assume you already got the basics of PHP programming skills. &lt;/p&gt;

&lt;p&gt;Also, I’d like to stress the difference between email &lt;a href="https://mailtrap.io/blog/email-validation/"&gt;validation&lt;/a&gt; and &lt;a href="https://mailtrap.io/blog/email-verification/"&gt;verification&lt;/a&gt;. Validation is about the correct formatting of an email address, and it’s a part of verification. It can be done on the server and the client side and I’ll focus on the server side here (no JavaScript, HTML, etc). &lt;/p&gt;

&lt;p&gt;So, let’s get to coding.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The exemplary scripts are based on PHP 8.3.6, and may not work on PHP 7.x.y versions. &lt;/p&gt;

&lt;h2&gt;
  
  
  PHP email validation function: filter_var()
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;filter_var()&lt;/code&gt; function is part of PHP’s filter extension, which provides a convenient way to perform validation and sanitization of various data types using a single function call. &lt;/p&gt;

&lt;p&gt;For email validation, &lt;code&gt;filter_var()&lt;/code&gt; offers a straightforward, reliable method to quickly assess whether an email address is valid according to PHP standards. For instance, you could integrate it with email form validation on your website. &lt;/p&gt;

&lt;p&gt;Here, I won’t cover the frontend stuff, input fields, and all. I already created an extensive &lt;a href="https://mailtrap.io/blog/php-form-validation/"&gt;PHP form validation guide&lt;/a&gt;, so feel free to check it out. &lt;/p&gt;

&lt;p&gt;Anyway, the &lt;code&gt;FILTER_SANITIZE_EMAIL&lt;/code&gt; (as part of ‘filter_var’ function) is engineered to remove characters not permitted in email addresses. This includes, but is not limited to: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spaces, &lt;/li&gt;
&lt;li&gt;Commas &lt;/li&gt;
&lt;li&gt;Certain special characters (/, |, #, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The primary purpose of sanitizing email inputs is to ensure that the data is clean and safe to be processed or stored. This is important when the data gets displayed on a web page, or is included in database queries. The reason is that it helps prevent XSS (Cross-Site Scripting) and SQL injection attacks.&lt;/p&gt;

&lt;p&gt;Here’s a practical example of how to sanitize an email input using &lt;code&gt;filter_var()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
// Example email input
$userInputEmail = "john.doe@example.com&amp;lt;script&amp;gt;alert('XSS');&amp;lt;/script&amp;gt;";

// Sanitize the email input
$sanitizedEmail = filter_var($userInputEmail, FILTER_SANITIZE_EMAIL);

echo "Original: " . $userInputEmail . "&amp;lt;br&amp;gt;";
echo "Sanitized: " . $sanitizedEmail;
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the script tag would be removed from the email input, displaying the sanitized version as &lt;a href="mailto:john.doe@example.com"&gt;john.doe@example.com&lt;/a&gt;. It shows how &lt;code&gt;FILTER_SANITIZE_EMAIL&lt;/code&gt; strips unwanted and potentially harmful characters from email inputs. &lt;/p&gt;

&lt;p&gt;Following this, you would typically validate the sanitized email to ensure it meets the format standards for a valid email address, which I’ll discuss next using &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Validating emails with &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt; checks whether the given string conforms to the format of a valid email address. It ensures the email address includes a valid username, an @ symbol, and a valid domain name with a domain extension.&lt;/p&gt;

&lt;p&gt;Simply, &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt; enforces proper email format standards. And here’s what the standards typically include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A username – can contain letters, numbers, dots, hyphens, and underscores.&lt;/li&gt;
&lt;li&gt;An @ symbol as a separator.&lt;/li&gt;
&lt;li&gt;A domain name that includes letters and may contain dots or hyphens.&lt;/li&gt;
&lt;li&gt;A domain extension, which must be at least two characters long and primarily contain letters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While very effective for basic validation, the filter has some limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unicode characters&lt;/strong&gt;: It does not support email addresses with international characters outside of the basic Latin alphabet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Advanced formats&lt;/strong&gt;: Certain valid email formats as per the Internet standards (&lt;a href="https://datatracker.ietf.org/doc/html/rfc2822"&gt;RFC standards&lt;/a&gt;) may not be recognized by this filter, such as emails with quoted strings or certain special characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The limitations indicate that &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt; may not suffice for applications requiring robust internationalization or adherence to the latest email address standards.&lt;/p&gt;

&lt;p&gt;But no worries, I’ll tell you how to overcome that under the &lt;a href="https://mailtrap.io/blog/php-email-validation/#using-api"&gt;Email validation in PHP using API section&lt;/a&gt;. Here’s a practical example of how to use the filter for basic validation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
// Example email input
$userInputEmail = "john.doe@example.com";

// Validate the email input
if (filter_var($userInputEmail, FILTER_VALIDATE_EMAIL)) {
    echo "The email address '$userInputEmail' is considered valid.";
} else {
    echo "The email address '$userInputEmail' is considered invalid.";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To wrap up, I’d like to give you some tips on how to handle verification failures without annoying your users. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User feedback&lt;/strong&gt;: Just an “Invalid email address” message won’t suffice. Provide clear and constructive feedback to users, helping them understand why their email was invalid and what they can do to correct it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging&lt;/strong&gt;: Keep logs of failed validation attempts for debugging purposes or to identify potential misuse of the system. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alternative validation&lt;/strong&gt;: Consider alternative methods of validation for special cases, such as allowing list-specific addresses or domain-specific addresses&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Regular expression for email validation in PHP
&lt;/h2&gt;

&lt;p&gt;Regular expressions (regex) offer a flexible method for validating email addresses in a PHP function. &lt;/p&gt;

&lt;p&gt;For instance, this approach works nicely in scenarios where you might need to validate emails based on specific criteria that are not covered by &lt;code&gt;FILTER_VALIDATE_EMAIL&lt;/code&gt;, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Restricting email addresses to certain domains.&lt;/li&gt;
&lt;li&gt;Enforcing specific prefixes or suffixes in the email username.&lt;/li&gt;
&lt;li&gt;Allowing newer top-level domains (TLDs) or internationalized domain names.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, regex can be used to implement complex pattern-matching rules necessary for applications requiring precise control over the user input.&lt;/p&gt;

&lt;p&gt;Now, I’ll show you how to create and integrate a regex. But before that, I’d have to touch upon the components of an email address as defined by the RFC 5322 standard. It helps wrap your mind around pattern-matching syntax for email validation use cases.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local part&lt;/strong&gt;: The local part of the email (before the @ symbol) may include a variety of characters (a-z, A-Z, 0-9) including special characters such as . (dot), – (hyphen), and _ (underscore). It can also contain quoted strings allowing almost any character within the quotes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain part&lt;/strong&gt;: The domain part (after the @ symbol) typically includes alphanumeric characters and may include hyphens and dots. The domain must not start or end with a hyphen.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an example of a pattern that matches the given standards.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$email = "test@example.com";
$pattern = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';

if (preg_match($pattern, $email)) {
    echo "The email address '$email' is considered valid.";
} else {
    echo "The email address '$email' is considered invalid.";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The regex matches the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One or more characters in the local part, including alphanumeric characters and special characters (._%+-).&lt;/li&gt;
&lt;li&gt;An @ symbol, separating the local and domain parts.&lt;/li&gt;
&lt;li&gt;A domain part consisting of one or more alphanumeric characters, potentially including dots and hyphens.&lt;/li&gt;
&lt;li&gt;A top-level domain (TLD) that must be at least two characters long.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So far so good, but if you need a more custom thing, here are a couple of suggestions on how to tweak the function filters. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Tighten the criteria&lt;/strong&gt;: Restrict the email to specific domains or subdomains by replacing the domain part of the pattern with a literal string (e.g., example.com).
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example for tightened criteria: Only allowing emails from specific domains
$pattern = '/^[a-zA-Z0-9._%+-]+@(example\.com|example\.net)$/';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Relax the criteria&lt;/strong&gt;: Allow additional characters in the local part or more variations in the TLD.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example for a relaxed criteria: Allowing international characters in the local part
$pattern = '/^[a-zA-Z0-9._%+-\p{L}]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/u';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though regexes provide significant control over input validation, it’s vital to test thoroughly (I’ll cover that in a second) to ensure that the pattern meets all functional requirements. The goal is to avoid excluding valid emails or including invalid ones inadvertently.&lt;/p&gt;

&lt;p&gt;This is how you might approach testing a regex pattern for email validation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$emails = [
    "test@example.com", // Valid
    "test.example@com", // Invalid: no top-level domain
    "test_example.com", // Invalid: missing '@'
    "test@example.com.", // Invalid: dot at the end of the domain
    "ñandu@dominio.com" // Valid if Unicode is considered
];

$pattern = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';

foreach ($emails as $email) {
    if (preg_match($pattern, $email)) {
        echo "The email address '$email' is valid.\n";
    } else {
        echo "The email address '$email' is invalid.\n";
    }
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you should consider debugging, check the tips to follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use online regex testers&lt;/strong&gt;: Tools like &lt;a href="https://regex101.com/"&gt;Regex101&lt;/a&gt; or &lt;a href="https://regexr.com/"&gt;RegExr&lt;/a&gt; can help visualize how your regex matches against test strings, providing explanations and highlighting potential issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log troublesome inputs&lt;/strong&gt;: When a user input fails validation, log the input for review. This can help identify what the regex may be failing to catch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unit testing&lt;/strong&gt;: Implement unit tests to automatically check the regex against known valid and invalid emails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As regexes can be a blessing and a curse, I’ll finish this section with some best practices and common mishaps. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep it readable&lt;/strong&gt;: While regex can be compact, overly complex patterns can become unreadable and difficult to maintain. Use comments and break complex patterns into smaller parts if necessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use non-capturing groups&lt;/strong&gt;: Unless you need to capture parts of the email for later use in the code, use non-capturing groups&lt;code&gt;(?: ...)&lt;/code&gt; to avoid unnecessary performance overhead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specify character ranges explicitly&lt;/strong&gt;: Avoid using broad classes like ‘&lt;code&gt;.\*&lt;/code&gt;’ when validating emails. Instead, encode exactly which characters are allowed in each part of the email.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use anchors&lt;/strong&gt;: Always use &lt;code&gt;^&lt;/code&gt; (start of string) and &lt;code&gt;$&lt;/code&gt; (end of string) anchors to ensure that the entire string matches the pattern, preventing partial matches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** Common Mishaps:**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Escaping characters&lt;/strong&gt;: Failing to escape special regex characters like &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, and &lt;code&gt;+&lt;/code&gt; can lead to unintended matches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance issues&lt;/strong&gt;: Regex that uses excessive backtracking (e.g., nested quantifiers like &lt;code&gt;(a+)+)&lt;/code&gt; can cause performance issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unicode ignorance&lt;/strong&gt;: If international characters are a requirement, forgetting to handle Unicode properly can exclude valid emails with international characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Email validation in PHP using API
&lt;/h2&gt;

&lt;p&gt;APIs offer advanced capabilities beyond what local methods can provide, and here’s what they are. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced accuracy&lt;/strong&gt;: APIs often use sophisticated algorithms with a real-time data lookup that goes beyond simple format validation. They can check if an email address is correctly formatted and verify it (confirm the address exists and can receive emails).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduce local resource usage&lt;/strong&gt;: Offloading the validation process to an external service can reduce the load on your local systems, which is beneficial for applications with high volumes of email processing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access to additional data&lt;/strong&gt;: Some APIs also offer information like whether the email is a disposable address, its risk score for being spam, or its general reputation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this tutorial, I’ll discuss a generic approach to integrating an email validation API. While specific details can vary between providers, the general principles of making a request and handling a response are similar across most services.&lt;/p&gt;

&lt;p&gt;I assume that you already chose an email validation API provider and obtained their API credentials. So, here’s how to implement the request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$email = "test@example.com";
$apiKey = "YOUR_API_KEY";
$apiUrl = "https://api.emailvalidator.com/validate?apiKey={$apiKey}&amp;amp;email={$email}";

$response = file_get_contents($apiUrl);
if ($response !== false) {
    $data = json_decode($response, true);
    print_r($data);
} else {
    echo "API request failed.";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this scenario, it’s also important to handle API responses properly and manage errors. The responses usually come in JSON format containing various fields indicating the validation results. You need to parse these responses and react accordingly in your application logic.&lt;/p&gt;

&lt;p&gt;As for managing errors, you should cover network issues, invalid API keys, or exceeded rate limits. Use try-catch blocks or check for errors in the response to ensure robustness. Here’s an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
try {
    $response = file_get_contents($apiUrl);
    if ($response === false) {
        throw new Exception("API request failed.");
    }
    $data = json_decode($response, true);
    if (isset($data['error'])) {
        throw new Exception("Error from API: " . $data['error']);
    }
    print_r($data);
} catch (Exception $e) {
    echo "An error occurred: " . $e-&amp;gt;getMessage();
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Email validation as part of email testing
&lt;/h2&gt;

&lt;p&gt;I won’t beat around the bush, here are four main reasons to validate addresses when testing emails. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Deliverability, deliverability, and always deliverability&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By verifying that an email address is formatted correctly and is valid, you reduce the risk of sending emails to non-existent addresses, which can hurt your sender’s reputation and impact deliverability.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Spam compliance&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sending emails to invalid addresses frequently leads to higher bounce rates, which are monitored by Internet Service Providers (ISPs). Consequently, it can lead to blacklisting of your sending IP address. By ensuring that email addresses are valid, you avoid penalties associated with violating spam laws (CAN-SPAM and GDPR).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Improved quality of user data&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Regular email validation as part of email testing helps maintain high-quality user data. Clean, validated email lists improve the effectiveness of email marketing campaigns and reduce the cost associated with managing undeliverable emails.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Automation&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Automating email validation processes can significantly enhance the efficiency and reliability of your email testing strategies. Automation ensures that email validation checks are performed consistently, without manual intervention, making the processes scalable and error-resistant.&lt;/p&gt;

&lt;p&gt;Of course, there are specific tools and techniques to automate email tests. First, I’ll cover &lt;a href="https://mailtrap.io/email-sandbox/"&gt;Mailtrap Email Testing&lt;/a&gt;, part of &lt;a href="https://mailtrap.io/"&gt;Mailtrap Email Delivery Platform&lt;/a&gt;. Then, I’ll talk about dedicated validation services, custom scripts, and cron jobs.&lt;br&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AveaJc6c3fI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Mailtrap Email Testing is an email sandbox to inspect and debug emails in staging, dev, and QA environments before sending them to recipients. &lt;/p&gt;

&lt;p&gt;I need to stress that the sandbox doesn’t include email validation. However, you can run a custom validation script and a cron job in parallel with Mailtrap Email Testing. Or you could check the addresses just before sending the emails on production. &lt;/p&gt;

&lt;p&gt;This is particularly useful if you use &lt;a href="https://api-docs.mailtrap.io/docs/mailtrap-api-docs/a2041e813d169-email-testing-api"&gt;Mailtrap Testing API&lt;/a&gt;, which allows you to easily test templates and automate QA processes. Then, you can switch from sandbox to production environment and keep sending to valid addresses. &lt;/p&gt;

&lt;p&gt;Aside from a reliable REST API, and a fake SMTP server, you also get the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML/CSS check&lt;/li&gt;
&lt;li&gt;Spam score check&lt;/li&gt;
&lt;li&gt;API for QA automation&lt;/li&gt;
&lt;li&gt;Ready-to-use integrations in 20+ languages (Ruby, Python, PHP, Node.js, .Net, etc.)&lt;/li&gt;
&lt;li&gt;Emails preview&lt;/li&gt;
&lt;li&gt;Multiple inboxes for different projects and stages&lt;/li&gt;
&lt;li&gt;User management, SSO&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lastly, the whole setup is straightforward, you just need to do the following: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://mailtrap.io/register/signup?ref=header"&gt;Sign up for Mailtrap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;Email Testing &amp;gt; Inboxes &amp;gt; My Inbox&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Choose your preferred integration or copy-paste SMTP credentials to your project&lt;/li&gt;
&lt;li&gt;Run the code and get the test email in an instant&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnej5y52wyvjq521kxl5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnej5y52wyvjq521kxl5u.png" alt="Image description" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, here’s a custom PHP email validation script that can be run as a cron job to validate email addresses with a third-party API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
function validateEmail($email) {
    $apiKey = 'YOUR_API_KEY';
    $apiUrl = "https://api.emailvalidator.com/validate?apiKey={$apiKey}&amp;amp;email={$email}";

    $response = file_get_contents($apiUrl);
    if ($response !== false) {
        $data = json_decode($response, true);
        return $data['isValid'];
    }
    return false;
}

// Example email to validate
$email = 'test@example.com';
if (validateEmail($email)) {
    echo "Email is valid.\n";
} else {
    echo "Email is invalid.\n";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, here’s how to automate the whole thing with a cron job on a Linux server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 1 * * * /usr/bin/php /path/to/your/script.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The job runs the script once a day at 1:00 AM. &lt;/p&gt;

&lt;p&gt;Now, your task is to set up all the automation, sit back and relax knowing your domain and IP reputations are safe. &lt;/p&gt;

&lt;p&gt;We appreciate the you chose this article to know more about PHP email validation. If you want to find more interesting content on related topics, follow &lt;a href="https://mailtrap.io/blog/php-email-validation/"&gt;Mailtrap blog&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>emailvalidation</category>
      <category>php</category>
    </item>
    <item>
      <title>Creating a WordPress Contact Form – Complete Guide</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Wed, 17 Apr 2024 05:17:18 +0000</pubDate>
      <link>https://forem.com/veljkoristic/creating-a-wordpress-contact-form-complete-guide-1d1j</link>
      <guid>https://forem.com/veljkoristic/creating-a-wordpress-contact-form-complete-guide-1d1j</guid>
      <description>&lt;p&gt;I’ll make you an offer you can’t refuse. 🐈&lt;/p&gt;

&lt;p&gt;I’ll tell you how to create a WordPress contact form, covering every imaginable detail, and making sure you won’t be reading only code and industry jargon. &lt;/p&gt;

&lt;p&gt;So, this article is suitable for beginners and those who already have some experience and wish to get the most from a basic contact form in terms of security and user experience. &lt;/p&gt;

&lt;p&gt;Now, get your fingers cracking and let’s start.  &lt;/p&gt;

&lt;h2&gt;
  
  
  How to create a contact form in WordPress with a plugin?
&lt;/h2&gt;

&lt;p&gt;The contact form plugin method is the simplest and fastest. Though there are some security limitations and plugins aren’t as flexible as coding stuff yourself. &lt;/p&gt;

&lt;p&gt;Here I’ll use WPForms (the WPForms Lite – free version) as it’s most reliable and straightforward. Another honourable option to consider is Ninja Forms. &lt;/p&gt;

&lt;p&gt;Whichever plugin you choose, it might be worth considering installing auxiliary add-ons like Jetpack for advanced spam control and security. I won’t be going into details of that here, since I cover security, validation, and sanitization the fun way – I tell you how to code it yourself. 😀&lt;/p&gt;

&lt;p&gt;Here goes the step-by-step tut to install and use arguably the best WordPress contact form plugin. &lt;/p&gt;

&lt;p&gt;Step 1: Install and Activate the WPForms Plugin&lt;br&gt;
Go to the sidebar WordPress admin panel. Then, navigate to Plugins &amp;gt; Add New, look for “WPForms“.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg69tauz8z2ajbtvnt2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg69tauz8z2ajbtvnt2r.png" alt="Image description" width="549" height="301"&gt;&lt;/a&gt;&lt;br&gt;
Now, click on the grey Install Now button next to the plugin called Contact Form by WPForms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i6nnitg6frz93pr75y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i6nnitg6frz93pr75y0.png" alt="Image description" width="549" height="301"&gt;&lt;/a&gt;&lt;br&gt;
The last thing to do is activate the plugin. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8yorg5cex9ty88ohqlxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8yorg5cex9ty88ohqlxb.png" alt="Image description" width="549" height="325"&gt;&lt;/a&gt;&lt;br&gt;
Step 2: Create a New Contact Form&lt;br&gt;
After activating WPForms, navigate to WPForms &amp;gt; All Forms in the WordPress dashboard. Then, click the Add New button to open the WPForms drag-and-drop form builder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foctn8d9hr6yyqeje9kes.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foctn8d9hr6yyqeje9kes.png" alt="Image description" width="800" height="591"&gt;&lt;/a&gt;&lt;br&gt;
In the form builder plugin, give your contact form a name, then select the contact form template. WPForms Lite comes with a few free form templates. &lt;/p&gt;

&lt;p&gt;For simplicity, I selected the Simple Contact Form template; it’ll automatically add the Name, Email, and Message fields. But if you’re a small business or ecommerce, the RFQ, Billing, or newsletter signup forms would also work. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxk3lv3milwx41scrm4ir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxk3lv3milwx41scrm4ir.png" alt="Image description" width="800" height="230"&gt;&lt;/a&gt;&lt;br&gt;
Step 3: Customize your form&lt;br&gt;
Click on a form field to bring up a Field Options panel on the left to make changes to the field label or other form settings. You can also use your mouse to drag and drop the fields to change the order. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjufgiafubqzxuodb2td.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjufgiafubqzxuodb2td.png" alt="Image description" width="800" height="306"&gt;&lt;/a&gt;&lt;br&gt;
Here, I’m doing a user-friendly Contact Us form without fancy fields. You can create any other type of registration form and align it with your WordPress themes if necessary. &lt;/p&gt;

&lt;p&gt;Pro Tip: Don’t go overboard with the fields as it’ll affect form submissions. 3 to 5 fields is usually more than enough. &lt;/p&gt;

&lt;p&gt;Step 4: Save your form&lt;br&gt;
Once you’re done customizing your form, make sure to click the Save button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h8wjm9tmzeuyls9eb7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8h8wjm9tmzeuyls9eb7g.png" alt="Image description" width="800" height="161"&gt;&lt;/a&gt;&lt;br&gt;
Step 5: How to add a contact form to a Page&lt;br&gt;
You can add it to an existing contact page or create a new page in WordPress. To create a new contact form page, go to Pages &amp;gt; Add New and give your page a name.&lt;/p&gt;

&lt;p&gt;Use the WPForms block to add the form to the page.&lt;/p&gt;

&lt;p&gt;Click the Plus add block button and search for WPForms. Select the simple form you created earlier from the drop-down menu. WPForms will load the contact form preview inside the editor. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukjiii2sirlcog161qmn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukjiii2sirlcog161qmn.png" alt="Image description" width="800" height="306"&gt;&lt;/a&gt;&lt;br&gt;
Finally, click Publish or Update to save your form.&lt;/p&gt;

&lt;p&gt;Step 6: Using WordPress plugin shortcodes&lt;br&gt;
WPForms comes with a WordPress contact form shortcode. You can use it by visiting WPForms &amp;gt; All Forms and then copying the shortcode next to your form. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndl4s0w5szhypkj1rb2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndl4s0w5szhypkj1rb2z.png" alt="Image description" width="800" height="233"&gt;&lt;/a&gt;&lt;br&gt;
Open the page builder where you want to add the shortcode, click the Plus add block button, and search for “Shortcode”. &lt;/p&gt;

&lt;p&gt;Paste the shortcode that you copied above into the box, then click Update or Publish. &lt;/p&gt;
&lt;h2&gt;
  
  
  How to create a simple contact form in WordPress without a plugin?
&lt;/h2&gt;

&lt;p&gt;Here, I’ll tell you how to create more advanced forms without any plugins. With that, you’ll have more control over the email notifications from the form itself. &lt;/p&gt;

&lt;p&gt;Note: This is one of WordPress tutorials that assumes you have basic coding skills. &lt;/p&gt;

&lt;p&gt;Step 1: Create a new HTML form inside WP Pages&lt;br&gt;
You can add the form to an existing page or create a new one. &lt;/p&gt;

&lt;p&gt;To create a new contact form page, go to Pages &amp;gt; Add New and give your page a name. Afterward, click add block “Custom HTML”&lt;/p&gt;

&lt;p&gt;Step 2: Create the HTML structure of the contact form&lt;br&gt;
Create the HTML structure of your contact form. Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form id="contact-form" action="/wp-admin/admin-post.php" method="post"&amp;gt;
    &amp;lt;input type="hidden" name="action" value="submit_contact_form"&amp;gt;
    &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
    &amp;lt;input type="text" name="name" id="name" required&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
    &amp;lt;input type="email" name="email" id="email" required&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
    &amp;lt;textarea name="message" id="message" required&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The form contains, Name, Email, and Message fields, and a form button for submitting the form. But if you want to go super fancy you could also add some conditional logic, pull data from a CRM, add checkbox, etc.  &lt;/p&gt;

&lt;p&gt;Note: The super fancy stuff would require quite a bit of coding and integration of third-party APIs into the PHP structure of your WordPress site. &lt;/p&gt;

&lt;p&gt;Intermediary step: Custom CSS styles&lt;br&gt;
The default HTML style looks a bit bland. Here’s a sample CSS to beautify the form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
#contact-form {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 5px;
}

#contact-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

#contact-form input[type="text"],
#contact-form input[type="email"],
#contact-form textarea {
    width: 90%;
    padding: 10px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

#contact-form input[type="submit"] {
    background-color: #007BFF;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#contact-form input[type="submit"]:hover {
    background-color: #0056b3;
}
&amp;lt;/style&amp;gt;

&amp;lt;form id="contact-form" action="/wp-admin/admin-post.php" method="post"&amp;gt;
    &amp;lt;input type="hidden" name="action" value="submit_contact_form"&amp;gt;
    &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
    &amp;lt;input type="text" name="name" id="name" required&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
    &amp;lt;input type="email" name="email" id="email" required&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
    &amp;lt;textarea name="message" id="message" required&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note/Advanced Tip:&lt;/p&gt;

&lt;p&gt;The basic HTML form I created already accepts the styles. The &lt;code&gt;style&lt;/code&gt; tag at the beginning of the HTML contains the CSS rules that style the form. These rules apply to all elements within the #contact-form element because of the way CSS works.&lt;/p&gt;

&lt;p&gt;However, if you want to separate the CSS from the HTML, you can move the CSS code to a separate .css file and link it to your HTML file. Here’s how you can do it:&lt;/p&gt;

&lt;p&gt;Create a new .css file in your theme directory, let’s call it custom_form.css. Copy the CSS rules from the &lt;code&gt;style&lt;/code&gt; tag and paste them into this file.&lt;br&gt;
Link the CSS file in your HTML file. You can do this by adding a &lt;code&gt;link&lt;/code&gt; tag in the &lt;code&gt;head&lt;/code&gt; section of your HTML file. Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
    &amp;lt;!-- Other head elements --&amp;gt;
    &amp;lt;link rel="stylesheet" href="/path/to/your/theme/directory/custom_form.css"&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace /path/to/your/theme/directory/ with the actual path to your theme directory.&lt;br&gt;
Now, the styles defined in contact-form.css will be applied to your form.&lt;/p&gt;

&lt;p&gt;Step 3: Create a Function to Handle Form Submission&lt;br&gt;
In your theme’s functions.php file, add the following PHP function to handle form submission:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

/**
 * Some other theme functions
 */


function handle_contact_form_submission() {
    if( isset($_POST['action']) &amp;amp;&amp;amp; $_POST['action'] === 'submit_contact_form' ) {
        $name = sanitize_text_field( $_POST['name'] );
        $email = sanitize_email( $_POST['email'] );
        $message = sanitize_textarea_field( $_POST['message'] );
        $adminEmail = get_option( 'admin_email' );

        // Here, you can add your code to process the form data (e.g., send an email).
        wp_mail($adminEmail, sprintf("New message from %s email:%s", $name, $email), $message);

        // Redirect the user back to the main or contact page after form submission.
        wp_redirect( home_url('/') );
    }
}


add_action( 'admin_post_nopriv_submit_contact_form', 'handle_contact_form_submission' );
add_action( 'admin_post_submit_contact_form', 'handle_contact_form_submission' );


?&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: Don’t forget to sanitize and validate user input&lt;br&gt;
Before processing the form data, you should sanitize and validate it to protect your site from malicious inputs. WordPress provides several functions for this purpose, such as &lt;code&gt;sanitize_text_field()&lt;/code&gt;, &lt;code&gt;filter_var(),&lt;/code&gt; and &lt;code&gt;validate_email()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Pro Tip: If your form has to handle a file upload on top of other functionalities, you need to sanitize and validate that file as well. &lt;/p&gt;

&lt;p&gt;And congrats! You’ve created a contact form in WordPress without plugins and extra files.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a callback function with validations and a captcha
&lt;/h2&gt;

&lt;p&gt;Here, I’ll tell you how to create more advanced forms, get better spam protection, and improve user registration on your WordPress website with some JavaScript tricks&lt;/p&gt;

&lt;p&gt;This step is more secure and easier to maintain, with just a tiny code snippet. &lt;/p&gt;

&lt;p&gt;To make everything neat and speed up the integration process for a custom form, I’ll create a single PHP function from all the code discussed under creating a contact form without a plugin. &lt;/p&gt;

&lt;p&gt;Then, you can use the function as the callback function of the shortcode. Here are the steps:&lt;/p&gt;

&lt;p&gt;Step 1: Create a shortcode &lt;br&gt;
Create a shortcode that will output your form. This can be done in the functions.php file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_shortcode( 'custom_contact_form', 'custom_contact_form_shortcode' );
function custom_contact_form_shortcode() {
    // Code goes here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Shortcode function&lt;br&gt;
Inside the custom_contact_form_shortcode function, add the HTML structure of your contact form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function custom_contact_form_shortcode() {
    ob_start(); ?&amp;gt;
    &amp;lt;form id="contact-form" action="&amp;lt;?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?&amp;gt;" method="post"&amp;gt;
     &amp;lt;input type="hidden" name="action" value="submit_contact_form"&amp;gt;
     &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
     &amp;lt;input type="text" name="name" id="name" required&amp;gt;&amp;lt;br&amp;gt;
     &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
     &amp;lt;input type="email" name="email" id="email" required&amp;gt;&amp;lt;br&amp;gt;
     &amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
     &amp;lt;textarea name="message" id="message" required&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;
     &amp;lt;input type="submit" value="Submit"&amp;gt;
    &amp;lt;/form&amp;gt;

    &amp;lt;?php return ob_get_clean();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Handling form submissions&lt;br&gt;
While still inside the custom_contact_form_shortcode function, add the code to handle form submissions, validate data input and display messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function custom_contact_form_shortcode() {
    ob_start();

    if( isset($_POST['action']) &amp;amp;&amp;amp; $_POST['action'] === 'submit_contact_form' ) {
        $name = sanitize_text_field( $_POST['name'] );
        $email = sanitize_email( $_POST['email'] );
        $message = sanitize_textarea_field( $_POST['message'] );


        // Initialize an array to hold validation messages
        $validation_messages = [];

        // Validate the data
        if (strlen($name) === 0) {
            $validation_messages[] = 'Please enter a valid name.';
        }

        if (strlen($email) === 0 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $validation_messages[] = 'Please enter a valid email address.';
        }

        if (strlen($message) === 0) {
            $validation_messages[] = 'Please enter a valid message.';
        }

        // Check if there are any validation messages
        if (!empty($validation_messages)) {
            foreach ($validation_messages as $validation_message) {
                echo '&amp;lt;div class="validation-message"&amp;gt;' . esc_html($validation_message) . '&amp;lt;/div&amp;gt;';
            }
        } else {
            // If there are no validation messages, send the email
            $adminEmail = get_option( 'admin_email' );
            $headers = array('Content-Type: text/html; charset=UTF-8');
            wp_mail($adminEmail, 'New message from ' . $name, $message, $headers);
            echo '&amp;lt;div class="success-message"&amp;gt;Your message has been sent successfully.&amp;lt;/div&amp;gt;';
        }
    }

    // Code for the form goes here

    return ob_get_clean();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, after taking the time to create a callback function, you can just use[custom_contact_form] in your WordPress pages or posts, and the contact form will show up. &lt;/p&gt;

&lt;p&gt;Nevertheless, my form isn’t ideal yet. For instance, if a user types invalid info, the system gets executed on a reloaded page, so the data is lost. This is as annoying as a floating popup and will surely make people churn. &lt;/p&gt;

&lt;p&gt;But, it can be solved if I replicate the PHP validation with JavaScript. I’ll be covering that in the JavaScript validation section. &lt;/p&gt;

&lt;p&gt;Step 4 Add Captcha to contact form&lt;br&gt;
To implement reCaptcha, you’ll need to register your site on the Google reCaptcha website to get a site key and secret key. Then, you can add the reCaptcha widget to your form and verify the user’s response using the secret key.&lt;/p&gt;

&lt;p&gt;This may seem as an overkill, but bots are getting smarter, so CAPTCHA gives you the extra edge to ward off malicious submissions. &lt;/p&gt;

&lt;p&gt;Step 5: Implement CSRF protection&lt;br&gt;
To protect your form from Cross-Site Request Forgery (CSRF) attacks, you can use WordPress’s built-in CSRF API. &lt;/p&gt;

&lt;p&gt;First, you’ll need to generate a nonce (number used once) using the wp_nonce_field() function in your form. Then, you can verify the nonce in process-form.php using the wp_verify_nonce() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In your form
wp_nonce_field( 'submit_contact_form_nonce', 'submit_contact_form_nonce_field' );

// In custom_contact_form_shortcode
if (!isset($_POST[submit_contact_form_nonce_field]) || !wp_verify_nonce($_POST[submit_contact_form_nonce_field], submit_contact_form_nonce)) {
    die('Invalid request');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pro Tip: &lt;/p&gt;

&lt;p&gt;Some WordPress hosting providers may offer additional CSRF protection. However, this is typically done at the application level. So, you should better search wordpress.org for add-ons or libraries that fit your use case, or just implement the above. &lt;/p&gt;

&lt;p&gt;Step 6: Send Email&lt;br&gt;
Finally, you can send an email using the $wpdb-&amp;gt;get_row() function to retrieve the site administrator’s email address from the WordPress database, and the wp_mail() function to send the email.&lt;/p&gt;

&lt;p&gt;Note: This isn’t the best solution since the given function is notoriously unreliable. No worries, I’ll tell you how to implement a proper email-sending service and avoid wp_mail() limitations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$adminEmail = get_option( 'admin_email' );
$headers = ['Content-Type: text/html; charset=UTF-8'];
wp_mail($adminEmail, 'New message from ' . $name, $message, $headers);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading the snippet on &lt;a href="https://mailtrap.io/blog/wordpress-contact-form/"&gt;Creating a WordPress Contact Form&lt;/a&gt;, in order to get more information about JavaScript validation and sending email with WP contact form - read the full article on Mailtrap blog.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>wordpress</category>
    </item>
    <item>
      <title>How to Set up PHP Form Validation – Detailed Tutorial</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Fri, 29 Mar 2024 16:49:47 +0000</pubDate>
      <link>https://forem.com/veljkoristic/how-to-set-up-php-form-validation-detailed-tutorial-36j6</link>
      <guid>https://forem.com/veljkoristic/how-to-set-up-php-form-validation-detailed-tutorial-36j6</guid>
      <description>&lt;p&gt;PHP form validation helps maintain data integrity and security, preventing SQL injection, XSS, and other malicious attacks. &lt;/p&gt;

&lt;p&gt;From the user input perspective, it prevents issues such as storing incorrect or incomplete data in the database. Plus, users can get immediate feedback about the input’s correctness, which improves their experience with your product. &lt;/p&gt;

&lt;p&gt;In this article, we’ll cover different types of validation for a simple registration form, starting with a quick overview of the available options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing a PHP form validation method
&lt;/h2&gt;

&lt;p&gt;There are a few options to validate a PHP form – you can use a PHP script, Ajax, JS, or a database. &lt;/p&gt;

&lt;p&gt;I’ll briefly cover the benefits and challenges of each. Then, we’ll move to integration tutorials, including exemplary scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility and control over the validation process.&lt;/li&gt;
&lt;li&gt;Scripts can automate repetitive tasks such as data cleaning or analysis after form submission.&lt;/li&gt;
&lt;li&gt;They allow for custom processing and logic that may not be possible with standard form handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom scripts require maintenance and updates as requirements change or technology evolves.&lt;/li&gt;
&lt;li&gt;Potential for security vulnerabilities if not implemented securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  AJAX validation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AJAX allows asynchronous form submissions without page refreshes, providing a smoother user experience. &lt;br&gt;
It enables real-time validation and feedback, which can improve user engagement and reduce errors. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AJAX can add complexity to the development process due to specific syntax and logic.  May be challenging for developers unfamiliar with JavaScript and asynchronous operations.&lt;/li&gt;
&lt;li&gt;The functionality depends on JavaScript being enabled in the user’s browser, which may not always be the case. &lt;/li&gt;
&lt;li&gt;AJAX requests can be vulnerable to cross-site request forgery (CSRF) attacks unless properly secured.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  JavaScript validation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript provides immediate feedback to users, improving the user experience by catching errors before the form is submitted. &lt;/li&gt;
&lt;li&gt;By validating on the client side, you can reduce the load on your server since invalid forms won’t reach the server. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client-side validation can be easily bypassed by disabling JavaScript or manipulating the DOM, so it should never replace server-side validation. &lt;/li&gt;
&lt;li&gt;Not all browsers interpret JavaScript in the same way, which can lead to inconsistent behavior.&lt;/li&gt;
&lt;li&gt;May not be accessible to users with disabilities who rely on assistive technologies that might not work well with JavaScript.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Database validation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storing form data in a database ensures that the data is persistent and can be accessed later for various purposes. &lt;/li&gt;
&lt;li&gt;Databases are designed to handle large amounts of data and can scale as needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Challenges:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing to a database can be slower than other methods and can impact performance, especially if the database is not optimized. &lt;/li&gt;
&lt;li&gt;Managing database connections and queries adds complexity to the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the choice of method depends on the project’s specific needs, the resources available, and the development team’s expertise. &lt;/p&gt;

&lt;p&gt;Also, it’s important to implement multiple validation layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client-side for user experience &lt;/li&gt;
&lt;li&gt;Server-side for security &lt;/li&gt;
&lt;li&gt;Database interaction for data persistence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By combining these layers and incorporating sanitization practices, you can build robust and secure forms that enhance your application’s functionality and user experience. Additionally, consider exploring server-side validation libraries for streamlined implementation and advanced features.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to validate a form in PHP using script
&lt;/h2&gt;

&lt;p&gt;I’ll start with a basic PHP validation script as it’s one of the quickest methods to implement. &lt;/p&gt;

&lt;p&gt;In this PHP tutorial, I won’t be adding any CSS to the HTML entities as the main focus is on the email form validation. &lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 – Create an HTML form
&lt;/h3&gt;

&lt;p&gt;Design your form with the necessary fields and include a submit button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form method="post" action="validate.php"&amp;gt;
    Name: &amp;lt;input type="text" name="name"&amp;gt;&amp;lt;br&amp;gt;
    Email: &amp;lt;input type="text" name="email"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="submit" name="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 – Sanitize and validate Input
&lt;/h3&gt;

&lt;p&gt;At the beginning of your PHP script, sanitize and validate the input. Use the $_POST superglobal array to access the input field form data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    // Sanitize and validate name
    $name = test_input($_POST["name"]);
    $nameErr = "";
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
        $nameErr = "Only letters and white space allowed";
    }

    // Sanitize and validate email
    $email = test_input($_POST["email"]);
    $emailErr = "";
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $emailErr = "Invalid email format";
    }

    // ... Additional validation checks ...
}

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3 – Display Errors
&lt;/h3&gt;

&lt;p&gt;If there are validation errors, display them to the user. Otherwise, proceed with the form processing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ($nameErr != "" || $emailErr != "") {
    echo "&amp;lt;b&amp;gt;Error:&amp;lt;/b&amp;gt;";
    echo "&amp;lt;br&amp;gt;" . $nameErr;
    echo "&amp;lt;br&amp;gt;" . $emailErr;
} else {
    // Process the form data
    echo "Form submitted successfully";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pro Tips
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To prevent XSS attacks and preserve data integrity, you can use the php echo htmlspecialchars function. It also makes the validation compatible with different encodings like UTF-8. Here’s the exemplary snippet:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$userInput = "&amp;lt;script&amp;gt;alert('Hello!');&amp;lt;/script&amp;gt;";
echo htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If the form passes validation, you can process the data accordingly, such as inserting it into a database or sending an email. I’ll show you how to send an email later. &lt;/li&gt;
&lt;li&gt;To avoid repeating code, encapsulate the validation logic within functions or classes and reuse them across different forms.&lt;/li&gt;
&lt;li&gt;As your application and validation needs grow, consider structuring the validation using OOP logic. It makes the code more modular, and easier to maintain, and it improves code organization. Check the example below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class FormValidator {
    private $data;
    private $requiredFields = [];
    public function __construct($postData) {
        $this-&amp;gt;data = $postData;
    }

    public function validate() {
        // Common validation rules
        $this-&amp;gt;validateRequiredFields();
        $this-&amp;gt;validateEmailFormat();
        // Add more validation methods as needed
    }

    private function validateRequiredFields() {
        // Check if required fields are present
        foreach ($this-&amp;gt;requiredFields as $field) {
            if (empty($this-&amp;gt;data[$field])) {
                throw new Exception("{$field} is required.");
            }
        }
    }

    private function validateEmailFormat() {
        // Check if email field is in a valid format
        if (!filter_var($this-&amp;gt;data['email'], FILTER_VALIDATE_EMAIL)) {
            throw new Exception("Invalid email format.");
        }
    }

    // Define other validation methods...
}

// Usage
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $validator = new FormValidator($_POST);
    try {
        $validator-&amp;gt;validate();
        // If validation passes, process the form
    } catch (Exception $e) {
        echo $e-&amp;gt;getMessage();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If necessary you can add a checkbox or a radio button to the form, then validate that input. Here’s an example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Radio button validation
    if (!isset($_POST['gender']) || empty($_POST['gender'])) {
        echo "Gender selection is required.&amp;lt;br&amp;gt;";
    } else {
        $gender = $_POST['gender'];
        // You can add additional validation here if needed
    }

    // Checkbox validation
    if (!isset($_POST['terms']) || $_POST['terms'] !== 'agree') {
        echo "You must agree to the terms and conditions.&amp;lt;br&amp;gt;";
    } else {
        // User agreed to terms and conditions
    }

    // If no errors, process the form
    if (empty($errors)) {
        echo "Form submitted successfully.";
    }
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to validate a form in PHP using AJAX
&lt;/h2&gt;

&lt;p&gt;AJAX offers a smooth user experience indeed, but note that you’ll also need to implement server-side CSRF protection. I won’t be covering that in this article.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step1 – Create an HTML form
&lt;/h3&gt;

&lt;p&gt;Start with a simple form in your HTML file with the action set to a PHP script and the method set to POST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form id="contactForm" action="process.php" method="post"&amp;gt;
    Name: &amp;lt;input type="text" name="name" required&amp;gt;&amp;lt;br&amp;gt;
    Email: &amp;lt;input type="email" name="email" required&amp;gt;&amp;lt;br&amp;gt;
    Message: &amp;lt;textarea name="message" required&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;div id="response"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 – Use Javascript for AJAX submission
&lt;/h3&gt;

&lt;p&gt;Write a native Javascript function that prevents the default form submission and sends the form data via AJAX to the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const form = document.getElementById('contactForm');

form.addEventListener('submit', function(event) {
  event.preventDefault();

  const formData = new FormData(form);

  fetch(form.action, {
    method: 'POST',
    body: formData
  })
  .then(response =&amp;gt; response.text())
  .then(data =&amp;gt; {
    document.getElementById('response').innerHTML = data;
  })
  .catch(error =&amp;gt; {
    console.error('Error:', error);
  });
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3 – Handle form validation in PHP
&lt;/h3&gt;

&lt;p&gt;Create a process.php file to handle the form submission. Use PHP’s built-in functions like filter_var() to check for valid email address and trim() to remove extra spaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$name = trim(filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL));
$message = trim(filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING));

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Invalid email format";
} else {
      // Process the form data (using prepared statements for database interaction)

    echo "Form submitted successfully";
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to validate a form in PHP using JavaScript
&lt;/h2&gt;

&lt;p&gt;Similar to AJAX, JS is great for improved user experience, but you’ll still need to make sure the method can’t be manipulated. So it’s wise to implement server-side validation as well. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 – Create an HTML form
&lt;/h3&gt;

&lt;p&gt;Similar to the AJAX example, create a form in your HTML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form id="contactForm" action="process.php" method="post"&amp;gt;
    &amp;lt;!-- form fields --&amp;gt;
    &amp;lt;input type="submit" value="Submit"&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;div id="error"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 – Implement JavaScript validation
&lt;/h3&gt;

&lt;p&gt;Add a JavaScript function to validate the form fields before submission.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function validateForm() {
    var email = document.forms["contactForm"]["email"].value;
    var errorDiv = document.getElementById("error");

    if (!validateEmail(email)) {
        errorDiv.innerHTML = "Invalid email format";
        return false;
    } else {
        errorDiv.innerHTML = "";
        return true;
    }
}

function validateEmail(email) {
    var re = /^(([^&amp;lt;&amp;gt;()\[\]\\.,;:\s@"]+(\.[^&amp;lt;&amp;gt;()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(String(email).toLowerCase());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure that you also validate the data on the server side using PHP, as client-side validation can be bypassed. And make sure your PHP file is properly protected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The validation script contains a mile-long regex. It works, but it’s not exactly an example of best coding practice, and in a real-world scenario, you’d want to use a JS validation library to avoid false positives or negatives. Here’s an example with the email-validator lib:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import the email-validator library
var validator = require('email-validator');

function validateForm() {
    var email = document.forms["contactForm"]["email"].value;
    var errorDiv = document.getElementById("error");

    if (!validator.validate(email)) {
        errorDiv.innerHTML = "Invalid email format";
        return false;
    } else {
        errorDiv.innerHTML = "";
        return true;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  PHP form validation: more use cases
&lt;/h2&gt;

&lt;p&gt;Aside from what’s already covered, which is mostly email and name validation. There are several other form elements you may want to validate. Also, it’s advisable to include CAPTCHA with your forms to ward off bots. &lt;/p&gt;

&lt;p&gt;The quick tutorials below include CAPTCHA integration, empty field, phone number, and website validation. Depending on your specific use case, and the form you created, you probably won’t need all. &lt;/p&gt;

&lt;h3&gt;
  
  
  CAPTCHA
&lt;/h3&gt;

&lt;p&gt;As indicated, CAPTCHAs are used to verify that the user is human and not a bot. They typically involve solving a puzzle or identifying objects in images. Here’s how to integrate it. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Include a CAPTCHA library: Choose a library or service to generate the CAPTCHA image. Google’s reCAPTCHA is a popular choice.&lt;/li&gt;
&lt;li&gt;Generate CAPTCHA image: When the form is loaded, call the captcha library’s API to generate a captcha challenge.&lt;/li&gt;
&lt;li&gt;Embed CAPTCHA in the form: Display the CAPTCHA image in your form where users can see it.&lt;/li&gt;
&lt;li&gt;Validate CAPTCHA response: When the form is submitted, check the user’s response against the CAPTCHA library’s verification API.&lt;/li&gt;
&lt;li&gt;Handle verification result: If the captcha was solved correctly, continue processing the form. Otherwise, display an error message.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Want to find more code examples and information on &lt;a href="https://mailtrap.io/blog/php-form-validation/"&gt;PHP Form Validation&lt;/a&gt;? Check out an original post published on Mailtrap blog.&lt;/p&gt;

</description>
      <category>php</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Salesforce Apps to Keep Under Your Radar</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Mon, 18 Mar 2024 12:40:16 +0000</pubDate>
      <link>https://forem.com/veljkoristic/salesforce-apps-to-keep-under-your-radar-18md</link>
      <guid>https://forem.com/veljkoristic/salesforce-apps-to-keep-under-your-radar-18md</guid>
      <description>&lt;p&gt;Salesforce Apps, available through the Salesforce Appexchange, serve a diverse array of business services to help enhance your admins’ operational efficiency. &lt;/p&gt;

&lt;p&gt;Among the multitude of functionalities, the role of email infrastructure stands out as integral. And it touches upon critical aspects of your email flows, including: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Synchronization &lt;/li&gt;
&lt;li&gt;Analytics &lt;/li&gt;
&lt;li&gt;Templates &lt;/li&gt;
&lt;li&gt;Campaigns &lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Compliance&lt;/li&gt;
&lt;li&gt;Document generation and validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To explain it a bit simpler, Salesforce is about the seamless integration of email communication with customer data. In turn, you get to have personalized interactions with your clients. Also, you get to make informed business decisions based on those interactions. &lt;/p&gt;

&lt;p&gt;All things considered, it’s safe to say that the existence and usability of these apps also helped with widespread Salesforce adoption. &lt;/p&gt;

&lt;p&gt;Speculations aside, we delve into some of the most effective Salesforce applications for various components of your email infrastructure. So, let’s dive right in. &lt;/p&gt;

&lt;h2&gt;
  
  
  Best Salesforce Apps: A Quick Overview
&lt;/h2&gt;

&lt;p&gt;When evaluating Salesforce apps related to email infrastructure, it’s essential to keep in mind that the “best” app depends heavily on specific business needs and workflows. &lt;/p&gt;

&lt;p&gt;For example, sales cloud users looking for ways to improve their sales process might require different apps than service cloud users. But, to guide this exploration, we’ve considered the universal factors that contribute to an array of business workflows related to email infrastructure.&lt;/p&gt;

&lt;p&gt;Firstly, the &lt;strong&gt;features offered by the app play a significant role&lt;/strong&gt;. We looked for apps that provide a robust set of capabilities, giving users &lt;strong&gt;the flexibility to manage various aspects of email infrastructure&lt;/strong&gt; efficiently.&lt;/p&gt;

&lt;p&gt;Secondly, we took &lt;strong&gt;15+ years of our experience in building and maintaining email infrastructures&lt;/strong&gt; and distilled it into editorial chunks to give you a first-hand assessment of the given apps. &lt;/p&gt;

&lt;p&gt;We aim to gauge the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-world applications &lt;/li&gt;
&lt;li&gt;Reliability&lt;/li&gt;
&lt;li&gt;How the apps match up to their advertised promises.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, we’ve checked how these apps have aided businesses in solving their unique challenges.&lt;/p&gt;

&lt;p&gt;Finally, compatibility with Salesforce is a non-negotiable criterion. &lt;/p&gt;

&lt;p&gt;The chosen apps integrate seamlessly with Salesforce.com, ensuring users can conveniently leverage their capabilities within the CRM environment. &lt;/p&gt;

&lt;p&gt;However, some of the listed apps are paid-only and geared more towards advanced Salesforce org users, which with be explicitly stated within the review. Some also offer free options and, as there’s no free Salesforce, it’s a good way to test things out before you commit to a plan. &lt;/p&gt;

&lt;p&gt;Having accounted for all of the above, we’ve selected and categorized a range of Salesforce apps that excel in handling specific email infrastructure tasks. Read on for more details. &lt;/p&gt;

&lt;h2&gt;
  
  
  Salesforce Apps for Email Synchronization
&lt;/h2&gt;

&lt;p&gt;Efficient email synchronization is pivotal in streamlining your Salesforce operations, ensuring all relevant communication is captured and accessible within the platform. With these, you take the functionality of the Lightning app to the next level.  &lt;/p&gt;

&lt;p&gt;Anyway, here’s one of the top apps in this arena.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cirrus Insight
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.cirrusinsight.com/"&gt;Cirrus Insight&lt;/a&gt; acts as a bridge between the Salesforce environment and your inbox, reducing the tedious task of constantly flipping between email and Salesforce.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmyvjgqv634i171u2ko9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmyvjgqv634i171u2ko9v.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;The automatic sync of emails and attachments from your inbox to Salesforce truly stands out. It enables you to efficiently store and access every relevant piece of communication within Salesforce.&lt;/p&gt;

&lt;p&gt;Calendar Sync is another notable feature. It ensures all your meetings, calls, and events (like a webinar, for example) are synced between your email and Salesforce, providing frictionless scheduling and improved time management.&lt;/p&gt;

&lt;p&gt;Cirrus Insight also offers contextual Salesforce insights right in the inbox. With this feature, you can view and update Salesforce records without leaving your email, making for a more efficient workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;Indeed, the automatic sync feature is a significant productivity booster. We appreciate the ease of accessing Salesforce data right from the inbox. This will consistently shave off minutes from your workflow, leading to improved time efficiency. &lt;/p&gt;

&lt;p&gt;Now, we have to stress that there’s a bit of a learning curve, as this app is for intermediate to advanced users of the Marketing Cloud, and other Salesforce editions. The good news is that the app is well-documented, so you shouldn’t struggle to figure out the ropes. &lt;/p&gt;

&lt;h3&gt;
  
  
  Ebsta
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.ebsta.com/"&gt;Ebsta&lt;/a&gt; is another noteworthy app for email synchronization, designed to empower Salesforce users with greater control over their email management. Its core strength lies in the ability to sync and surface relevant Salesforce data directly in your inbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupde21qzlvd9r8xhax36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupde21qzlvd9r8xhax36.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;Comprehensive email synchronization is Ebsta’s strong suit. The app ensures that all your email conversations, events, and contacts are automatically synced with Salesforce. It also features a real-time activity tracking capability, enabling users to see who is engaging with their emails right away.&lt;/p&gt;

&lt;p&gt;Another standout feature is Ebsta’s cross-platform compatibility. Whether you’re using Gmail, Outlook, or another email client, Ebsta allows you to access crucial Salesforce data without leaving your inbox.&lt;/p&gt;

&lt;p&gt;Finally, Ebsta’s calendar synchronization provides the easy scheduling of meetings and events, which are then automatically updated in Salesforce. So, there’s less chance you’ll miss an important interaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;Again, we like Ebsta’s robust synchronization features, which can notably improve your workflow. The integration with various email clients is seamless, and real-time activity tracking can be a game-changer, particularly for your sales team. &lt;/p&gt;

&lt;p&gt;For instance, let’s imagine the interaction happens at an odd hour and your sales rep is out of the office. The rep could get a real-time notification on Salesforce Mobile, and act on it immediately. &lt;/p&gt;

&lt;p&gt;Lastly, we observed less of a learning curve compared to Cirrus Insight. But this is a highly subjective parameter, so take it with a grain of salt. &lt;/p&gt;

&lt;h2&gt;
  
  
  Salesforce Apps for Email Analytics
&lt;/h2&gt;

&lt;p&gt;When it comes to email infrastructure within Salesforce, having insightful analytics is indispensable. It allows for data-driven decisions, ensuring your communication strategy is aligned with your audience’s needs. Let’s explore one of the leading apps for email analytics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Full Circle Insights
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://fullcircleinsights.com/"&gt;Full Circle Insights&lt;/a&gt; is an app designed to offer robust email analytics within the Salesforce CRM. It aims to bridge the gap between data and insights, making it easier to understand your email engagement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pgwae1jgrjr7x6qbea3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pgwae1jgrjr7x6qbea3.png" alt="Image description" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;Full Circle Insights brings several key features to the table. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Response Management&lt;/strong&gt; – designed to provide a detailed understanding of your email performance, tracking engagement metrics such as opens, clicks, and conversions directly within Salesforce.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Campaign Influence&lt;/strong&gt; – lets you see the direct and indirect influence of your emails on sales opportunities, providing insights into the effectiveness of your email strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Funnel Metrics&lt;/strong&gt; – gives a comprehensive view of your sales funnel, helping you understand how emails contribute at each stage of the customer journey.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;Full Circle Insights provides a depth of analytics that could satisfy even the most demanding users. The Response Management feature, in particular, offers great granularity and accuracy. We also appreciate the sales funnel insights, which can be quite a helper in optimizing your email strategy. &lt;/p&gt;

&lt;p&gt;So, to no surprise, this Salesforce integration requires a certain level of expertise to fully exploit its capabilities. But once mastered, its potential to transform email strategy and inform business processes is undeniable.&lt;/p&gt;

&lt;p&gt;On that note, we should stress that this is an enterprise-level app, which is reflected in its pricing. &lt;/p&gt;

&lt;h2&gt;
  
  
  Salesforce Apps for Feedback and User Experience Management
&lt;/h2&gt;

&lt;p&gt;In the Salesforce landscape, receiving and managing customer feedback is crucial. It can inform and drive improvements to product features, services, and user experience. &lt;/p&gt;

&lt;p&gt;Here are two apps designed to simplify feedback collection and enhance user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Zonka Feedback
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.zonkafeedback.com/"&gt;Zonka Feedback&lt;/a&gt; is a comprehensive tool for capturing and analyzing feedback within Salesforce Lightning. Its primary objective is to help businesses measure customer sentiment and improve their overall experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcy85itzxctwjad0d68ii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcy85itzxctwjad0d68ii.png" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;Zonka offers real-time feedback capture, allowing you to respond quickly to customer needs. It supports various feedback channels, including email, SMS, and on-site feedback, giving your customers the flexibility to interact through their preferred channels.&lt;/p&gt;

&lt;p&gt;With its rich analytics, you can easily understand customer sentiment, identify trends, and track improvement over time. The app give you the option to set up instant notifications for specific feedback. In turn, you get to act immediately, when required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;The most useful Zonka features are multi-channel feedback collection and in-depth analytics. Plus, real-time feedback capture can have a significant impact on quick problem resolution, particularly for customer success and customer relationship teams. &lt;/p&gt;

&lt;p&gt;If we’re really nitpicky (which we aren’t), Zonka might benefit from more customization options. But overall, it’s among the best feedback apps, suitable for small businesses and enterprises alike. &lt;/p&gt;

&lt;h3&gt;
  
  
  Survicate
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://survicate.com/?utm_source=google&amp;amp;utm_medium=cpc&amp;amp;utm_campaign=survicate&amp;amp;utm_adgroup=brand&amp;amp;utm_term=survicateec&amp;amp;camp_id=354108535&amp;amp;adgroup_id=21487992055&amp;amp;ad_id=549742337202&amp;amp;hsa_tgt=kwd-342540695034&amp;amp;hsa_grp=21487992055&amp;amp;hsa_src=g&amp;amp;hsa_net=adwords&amp;amp;hsa_mt=e&amp;amp;hsa_ver=3&amp;amp;hsa_ad=549742337202&amp;amp;hsa_acc=6519365081&amp;amp;hsa_kw=survicate&amp;amp;hsa_cam=354108535&amp;amp;gclid=Cj0KCQiAgK2qBhCHARIsAGACuznN9ENe_dMWfRMKFqvsPTQGlfUvq47PhjXVbUbyzV7se2B0QRBaT58aAmgWEALw_wcB&amp;amp;gad_source=1"&gt;Survicate&lt;/a&gt; is a survey tool that allows you to collect continuous customer feedback via email, web, in-product, and mobile apps. It offers over 300 ready-to-use survey templates, including NPS, CSAT, and CES, making survey creation a breeze.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnslbvmbldkdzet8dujco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnslbvmbldkdzet8dujco.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;Integrating Salesforce and Survicate is a one-click, code-free process – there’s no need for complex technical configurations.&lt;/p&gt;

&lt;p&gt;With Survicate, you can seamlessly embed surveys directly into &lt;a href="https://mailtrap.io/blog/salesforce-mass-email/"&gt;Salesforce emails&lt;/a&gt;, enhancing your feedback collection process and enriching customer interactions. Users can conveniently share valuable insights without having to visit external platforms.&lt;/p&gt;

&lt;p&gt;As data between the two tools is synced in real time, survey responses are immediately accessible in Salesforce, which makes it easy to take prompt actions based on customer feedback.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;We like that Survicate captures every response, even if a user didn’t fill in every field, meaning you won’t lose any data. &lt;/p&gt;

&lt;p&gt;The transfer of contact attributes between Salesforce and Survicate is very easy indeed, and it helps you quickly filter survey insights and trigger workflows based on responses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jotform
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.jotform.com/salesforce-forms/"&gt;Jotform Salesforce Forms&lt;/a&gt; is a robust solution for creating and managing forms within the Salesforce ecosystem. It’s designed to streamline the sales process by automating form data synchronization with your Salesforce account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzdza9jpu653voe3of2x3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzdza9jpu653voe3of2x3.png" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;p&gt;The platform offers an intuitive &lt;a href="https://www.zonkafeedback.com/blog/best-form-builder-software-tools"&gt;form builder&lt;/a&gt;, enabling the creation of custom forms that seamlessly integrate with Salesforce. It’s great that you can start with ready-made templates and customize them fast. Plus, the forms are optimized for iOS and Android users.&lt;/p&gt;

&lt;p&gt;Also, the feature that allows sharing prefilled forms with customers is a standout because it simplifies the form-filling process a lot. And the automatic data sync with Salesforce CRM ensures that the data flow into your database is effortless.&lt;/p&gt;

&lt;p&gt;Additionally, Jotform offers an electronic signature collection through Jotform Sign. It can be a godsend for sales teams looking to expedite their deal closures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our Two Cents
&lt;/h3&gt;

&lt;p&gt;The ease of form creation and customization is a highlight indeed. And the same goes for automatic sync and prefilled forms. The reporting and analytics are adequate, but there’s room for more advanced analytical tools. Nonetheless, Jotform’s balance of simplicity and functionality makes it a great tool for Salesforce users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Salesforce Apps for Email Security and Compliance
&lt;/h2&gt;

&lt;p&gt;In the realm of Salesforce and the Appexchange apps, security and compliance are paramount. Keeping sensitive data safe and adhering to industry regulations can make a significant difference to your business’s credibility and trustworthiness. Here are the key apps that excel in these aspects.&lt;/p&gt;

&lt;h3&gt;
  
  
  OwnBackup
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.ownbackup.com/"&gt;OwnBackup&lt;/a&gt; is a comprehensive solution designed to protect your Salesforce data, including emails. It offers a suite of tools to ensure your email data remains secure and compliant with industry standards.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5zr1mstdmi4w4zw4irf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5zr1mstdmi4w4zw4irf.png" alt="Image description" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;At the core of OwnBackup is a robust backup and restore functionality. It automatically backs up data from the CRM platform, including emails, attachments, and metadata. In the event of data loss, you can restore custom objects or entire orgs without too much hassle.&lt;/p&gt;

&lt;p&gt;The app also offers a comprehensive suite of compliance tools. With features like audit trails and encrypted backups, OwnBackup helps you meet compliance standards such as GDPR and HIPAA.&lt;/p&gt;

&lt;p&gt;Finally, its Sandbox Seeding feature is a standout, letting you easily create and manage test data environments without compromising security or compliance. If you’re a SaaS, this feature will allow for more stable workflows, helping you remove preventable errors from production. &lt;/p&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;OwnBackup has backup-and-restore capabilities that can further streamline project management and completion. Also, its comprehensive compliance features can give you the peace of mind that both your static and in-transit data remain intact. &lt;/p&gt;

&lt;p&gt;Admittedly, the user interface could be a bit more intuitive. However, for such a robust security and compliance solution, it’s not a deal breaker by any means. &lt;/p&gt;

&lt;h3&gt;
  
  
  Cloud Compliance
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://cloudcompliance.app/"&gt;Cloud Compliance&lt;/a&gt; is a purpose-built app for Salesforce that provides an efficient solution for data privacy and compliance management. &lt;/p&gt;

&lt;p&gt;Basically, the app makes it simpler for you to meet complex regulatory requirements while ensuring the integrity of your email data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nshqtvgkpyodvajal8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nshqtvgkpyodvajal8t.png" alt="Image description" width="800" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Key features
&lt;/h3&gt;

&lt;p&gt;There’s a comprehensive suite of tools that help manage personal data in Salesforce. And here’s a quick scoop of what you might find most useful.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Discovery and Classification – allows you to locate and categorize personal data, aiding in GDPR and CCPA compliance.&lt;/li&gt;
&lt;li&gt;Data Retention and Deletion – enables you to set and automate data retention policies, ensuring unnecessary data doesn’t linger and contribute to compliance risks.&lt;/li&gt;
&lt;li&gt;Privacy Portal – allows data subjects to access and manage their data rights requests, further enhancing your compliance stance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Our two cents
&lt;/h3&gt;

&lt;p&gt;Cloud Compliance is a Salesforce native app, so there’s almost no learning curve, and you get the benefit of native integration. In plain English, if you understand Salesforce, you shouldn’t struggle with Cloud Compliance at all. &lt;/p&gt;

&lt;p&gt;To that, the efficiency and completeness of the compliance features are hard to rival. &lt;/p&gt;

&lt;p&gt;For instance, Data Discovery and Classification, along with automated Data Retention, are great aids in meeting GDPR and CCPA requirements. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Role of Mailtrap in the Salesforce Ecosystem
&lt;/h2&gt;

&lt;p&gt;In the Salesforce ecosystem, various apps bolster different aspects of email management. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://mailtrap.io/"&gt;Mailtrap&lt;/a&gt;, however, holds a distinct and multifaceted role in this arena. &lt;/p&gt;

&lt;p&gt;It’s an &lt;strong&gt;email delivery platform for businesses and individuals&lt;/strong&gt; that offers robust features to &lt;strong&gt;test, send, and control emails in one place&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5nfkyhakvd6q4mzcoh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5nfkyhakvd6q4mzcoh5.png" alt="Image description" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of Mailtrap
&lt;/h2&gt;

&lt;p&gt;As indicated, Mailtrap’s functionality extends beyond the bounds of testing, but first things first. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://mailtrap.io/email-sandbox/"&gt;Mailtrap Testing&lt;/a&gt; &lt;strong&gt;adds an email sandbox to your Salesforce toolbox&lt;/strong&gt; to help developers test and debug emails without the risk of email templates from staging ever reaching your recipients.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp28i60g72csm3idm87xb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp28i60g72csm3idm87xb.png" alt="Image description" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How?&lt;/p&gt;

&lt;p&gt;It goes like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We give you a fake SMTP server. &lt;/li&gt;
&lt;li&gt;The server captures outgoing test emails.
&lt;/li&gt;
&lt;li&gt;We analyze content for spam and validate HTML/CSS. &lt;/li&gt;
&lt;li&gt;The developers view errors, debug, then proceed to send highly-deliverable emails&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rxqvouuf02o0bigz0gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rxqvouuf02o0bigz0gb.png" alt="Image description" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sending part is, of course, covered by Mailtrap Email &lt;strong&gt;Sending functionality via API or SMTP&lt;/strong&gt;. It’s designed for transactional and bulk emails. Plus, there are five SDKs to integrate Mailtrap with your app quicker. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/railsware/mailtrap-nodejs"&gt;NodeJS SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/railsware/mailtrap-ruby"&gt;Ruby SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/railsware/mailtrap-php"&gt;PHP SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/railsware/mailtrap-python"&gt;Python SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/railsware/mailtrap-elixir"&gt;Elixir SDK&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On top of that, Mailtrap provides color-coded, user-friendly analytics, email templates, and webhooks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://mailtrap.io/register/signup?ref=header"&gt;Try Mailtrap Now&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How does it differ from the aforementioned apps?
&lt;/h3&gt;

&lt;p&gt;While other Salesforce apps focus on aspects such as synchronization, analytics, feedback, user experience, and security, Mailtrap brings &lt;strong&gt;a unique combination of pre-production email testing and robust email sending and analytics capabilities&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Also, there’s a technical difference. Unlike other apps in this article, Mailtrap integrates with Salesforce via Salesforce’s Email Relay feature. If you want to learn more about this, check our “&lt;a href="https://mailtrap.io/blog/salesforce-email-relay/"&gt;How to Set up Salesforce Email Relay&lt;/a&gt;” blog post. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Soon, you’ll be able to integrate Mailtrap Email Testing to Lightning Experience via AppExchange. &lt;/p&gt;

&lt;h3&gt;
  
  
  What added value does it bring to Salesforce users?
&lt;/h3&gt;

&lt;p&gt;We’re at liberty to stress that Mailtrap carves out a special niche in the Salesforce ecosystem. The key highlight is its ability to catch emails from the staging environment and also manage email production operations with just-in-time delivery.&lt;/p&gt;

&lt;p&gt;For Salesforce users, Mailtrap provides a unique blend of utility and control over their emails. As indicated, with Mailtrap email sandbox for testing, you can &lt;strong&gt;prevent unintended emails from reaching customers&lt;/strong&gt; during the development phase. &lt;/p&gt;

&lt;p&gt;Then, Mailtrap Email Sending allows you to send emails fast and reliably. It also offers comprehensive analytics, email templates, and &lt;a href="https://help.mailtrap.io/article/102-webhooks"&gt;webhooks&lt;/a&gt;. So you can have almost instant access to deliverability events and email data (assuming you use webhooks). And consequently, gain better control over your email infrastructure. &lt;/p&gt;

&lt;p&gt;All this results in more effective communication with existing customers, higher user adoption, and better customer support; leading to improved customer experience. &lt;/p&gt;

&lt;p&gt;And lastly, we’d need to point out that Mailtrap integrates with Salesforce using the Email Relays functionality, allowing for a seamless transition of data and operations between the two platforms. &lt;/p&gt;

&lt;h3&gt;
  
  
  What trends to look for with Salesforce apps?
&lt;/h3&gt;

&lt;p&gt;As the Salesforce ecosystem continues to adapt and expand, there are several trends worth keeping an eye on in relation to email infrastructure. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data management and security&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the growing emphasis on data privacy and regulations, we can expect to see even more sophisticated features dedicated to email security and compliance. This includes more advanced encryption methodologies, AI-powered anomaly detection, and improved auditing capabilities.&lt;/p&gt;

&lt;p&gt;For instance, Mailtrap is already using a state-of-the-art AI model for the following.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filter and block spammers and protect our IPs&lt;/li&gt;
&lt;li&gt;Run domain authentication and trustworthiness &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Integrations galore&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Integration is the key! Expect to see more Salesforce apps offering seamless integration with other platforms and tools. This trend is driven by the need for interconnected tools that provide users with like an all-in-one, streamlined workflow.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Y*&lt;em&gt;our users/customers are front-center&lt;/em&gt;* &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Undoubtedly, user experience will remain a primary focus. With an increasing demand for personalized customer experiences, email management tools will likely continue to evolve to allow for more personalized and &lt;a href="https://mailtrap.io/blog/interactive-emails/"&gt;interactive email templates&lt;/a&gt; and designs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus Tip&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://appexchange.salesforce.com/category/salesforce-labs-apps"&gt;Salesforce Labs&lt;/a&gt;, which we haven’t covered in this article, also offers plenty of free apps and integrations, some of which are designed as mobile apps. For example, we like the &lt;a href="https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000EFpAtUAL"&gt;Trail Tracker&lt;/a&gt; by Trailhead a lot, even though it’s not directly related to email infrastructure. But if you have a team that just migrated to Salesforce, it could really flatten the learning curve.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts and Conclusion
&lt;/h3&gt;

&lt;p&gt;When all’s said and done, Salesforce apps related to email infrastructure are integral components of an effective Salesforce strategy. &lt;/p&gt;

&lt;p&gt;Whether it’s for email synchronization, analytics, user experience management, security, compliance, or whatever you need; these apps provide a measurable value by enhancing efficiency and ensuring the integrity of your email operations.&lt;/p&gt;

&lt;p&gt;In this ever-evolving landscape, Mailtrap stands out with its unique combination of robust email testing and sending functionalities, making it an invaluable tool for any business using Salesforce.&lt;/p&gt;

&lt;p&gt;We appreciate the you chose this article to know about the most popular Salesforce apps. If you want to find more interesting content on related topics, &lt;a href="https://mailtrap.io/blog/best-salesforce-apps/"&gt;click here&lt;/a&gt;!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building an HTML email form – Frontend and Backend</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Tue, 05 Mar 2024 15:30:22 +0000</pubDate>
      <link>https://forem.com/veljkoristic/building-an-html-email-form-frontend-and-backend-43l</link>
      <guid>https://forem.com/veljkoristic/building-an-html-email-form-frontend-and-backend-43l</guid>
      <description>&lt;p&gt;There are two ways to create an HTML email form &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use the &lt;code&gt;mailto: address&lt;/code&gt; action element. &lt;/li&gt;
&lt;li&gt;Use backend script to handle data and send emails.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first method is something you shouldn’t try. Sending form data directly to an email from a web form without server-side processing isn’t recommended due to security and privacy risks. &lt;/p&gt;

&lt;p&gt;The following tutorial covers methods that include server-side scripting. And I added a special section to ensure that any sensitive information is encrypted and transmitted securely. &lt;/p&gt;

&lt;p&gt;First, I cover the front end that sends an HTTP POST request to the backend. Next, I go into the backend to send emails, using Laravel, Java, Node.js, Python, or C#.  Then, I’ll give you tips and some examples of security measures. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to create an HTML contact form – Quick guide
&lt;/h2&gt;

&lt;p&gt;As said, I’ll be covering the backend scripting for a few popular languages and frameworks. So, to make the HTML code easily integrated with the scripts, it’s critical to ensure the HTML form is universally compatible with each language. &lt;/p&gt;

&lt;p&gt;Here’s how to create a simple HTML form: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Form structure&lt;/strong&gt;&lt;br&gt;
Start with a basic HTML form structure. The action attribute should be set to a generic handler, which can be specified in the backend script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form action="process-form" method="post" enctype="multipart/form-data"&amp;gt;
  &amp;lt;!-- Form elements will go here --&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: The enctype="multipart/form-data" is important if you plan to include file uploads. It’s compatible with all backend technologies. The backend scripts also feature exemplary snippets without the support for file uploads. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Input elements *&lt;/em&gt;&lt;br&gt;
As needed, you can include the following elements.  &lt;/p&gt;

&lt;p&gt;Text fields&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
&amp;lt;input type="text" id="name" name="name"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Message field&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
&amp;lt;textarea id="message" name="message" rows="4" cols="50"&amp;gt;
&amp;lt;/textarea&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Message field notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;label for="message"&amp;gt;&lt;/code&gt;: This label is associated with the &lt;code&gt;textarea&lt;/code&gt;. The &lt;code&gt;for&lt;/code&gt; attribute should match the &lt;code&gt;id&lt;/code&gt;of the textarea, which helps with accessibility.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;: This is the element used for multi-line text input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;id="message"&lt;/code&gt;: The ID of the textarea, which is referenced by the label.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;name="message"&lt;/code&gt;: The &lt;code&gt;textarea&lt;/code&gt; name attribute is important as it’s the key that will be used to access this piece of data on the server side.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;rows="4"&lt;/code&gt; and &lt;code&gt;cols="50"&lt;/code&gt;: These attributes define the size of the &lt;code&gt;textarea&lt;/code&gt;. &lt;code&gt;rows&lt;/code&gt;specifies the number of lines, and &lt;code&gt;cols&lt;/code&gt; specifies the width in terms of character columns. You can adjust these numbers based on your layout requirements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Email field&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
&amp;lt;input type="email" id="email" name="email"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Submit button&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="submit" value="Submit"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Form action&lt;/strong&gt;&lt;br&gt;
The action attribute in the form should be a placeholder that will be replaced by the specific endpoint of your backend technology (Laravel, Java, Node.js, Python, or C#).&lt;/p&gt;

&lt;p&gt;For instance, in Laravel, you might set it to a route defined in your web routes, while in Node.js, it might point to an Express.js route.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backend integration (quick notes)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Laravel: Use a route in &lt;code&gt;web.php&lt;/code&gt; to handle the form submission.&lt;/li&gt;
&lt;li&gt;Java: Set up a servlet or a Spring Controller to process the form.&lt;/li&gt;
&lt;li&gt;Node.js: Use an Express.js route to handle the POST request.&lt;/li&gt;
&lt;li&gt;Python (Flask/Django): Define a view function or a Django view to process the form.&lt;/li&gt;
&lt;li&gt;C# (ASP.NET): Use a controller action in an ASP.NET MVC application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Processing form data&lt;/strong&gt;&lt;br&gt;
Each backend technology will have its way of accessing form data (e.g., &lt;code&gt;request.getParameter()&lt;/code&gt; in Java, &lt;code&gt;req.body&lt;/code&gt; in Node.js, &lt;code&gt;request.form&lt;/code&gt; in Flask).&lt;/p&gt;

&lt;p&gt;Ensure that the form data is properly validated and sanitized in the backend script to prevent security vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending emails&lt;/strong&gt;&lt;br&gt;
Each backend will have a different method for sending emails. Use the respective libraries or frameworks available for each technology.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro tips:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can also embed radio buttons or checkboxes in the form. Here I aimed for simplicity, focusing on the email and message, so there aren’t checkboxes and radio buttons. &lt;/li&gt;
&lt;li&gt;Consider implementing CAPTCHA to prevent spam submissions and confirm that the form is being filled out by a human. Later, I’ll show you how to integrate Google’s reCAPTCHA.&lt;/li&gt;
&lt;li&gt;It’s best to use a proper email-sending service like Mailtrap Email Delivery Platform to ensure your emails securely land at the desired address. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  HTML email form with CSS styles
&lt;/h3&gt;

&lt;p&gt;Without CSS, the form looks bland and might actually affect the conversions. So, I’ll make it more elegant, and the exemplary form below contains Name, Email, and Message fields, plus the Submit button. &lt;/p&gt;

&lt;p&gt;The HTML form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Contact Form&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        &amp;lt;form id="contact-form" action="process-form.php" method="post"&amp;gt;
            &amp;lt;div class="form-group"&amp;gt;
                &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" id="name" name="name" required&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="form-group"&amp;gt;
                &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
                &amp;lt;input type="email" id="email" name="email" required&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="form-group"&amp;gt;
                &amp;lt;label for="message"&amp;gt;Message:&amp;lt;/label&amp;gt;
                &amp;lt;textarea id="message" name="message" rows="4" required&amp;gt;&amp;lt;/textarea&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class="form-group"&amp;gt;
                &amp;lt;input type="submit" value="Submit"&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick Explainer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML Structure: The form is wrapped in a &lt;code&gt;div&lt;/code&gt; with a class &lt;code&gt;container&lt;/code&gt; for styling purposes. Each input field is enclosed in a div with a class &lt;code&gt;form-group&lt;/code&gt; for better control over spacing and layout.&lt;/li&gt;
&lt;li&gt;Required Fields: The &lt;code&gt;required&lt;/code&gt; attribute in the input fields ensures that the form cannot be submitted without filling these fields.
The CSS &lt;code&gt;(style.css)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
}

.container {
    width: 70%;
    margin: 30px auto;
    padding: 20px;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.form-group input[type="submit"] {
    background-color: #5cb85c;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.form-group input[type="submit"]:hover {
    background-color: #4cae4c;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick Explainer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;body&lt;/code&gt; style sets the font and background color of the page.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;container&lt;/code&gt; class styles the form’s container with a white background, centered alignment, and a subtle box shadow for a modern look.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;form-group&lt;/code&gt; class provides spacing between each form element.&lt;/li&gt;
&lt;li&gt;Input fields (&lt;code&gt;text&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;textarea&lt;/code&gt;) are styled to take full width with some padding and border-radius for a pleasant rounded corner look.
I changed the submit button type a bit. It’s styled with a green background color, which changes to a slightly darker green on hover for a subtle interactive effect.
Reminder: Replace &lt;code&gt;process-form.php&lt;/code&gt; (placeholder) in the form’s &lt;code&gt;action&lt;/code&gt; attribute with the actual script that will process the form data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JavaScript to enhance the form behavior
&lt;/h2&gt;

&lt;p&gt;HTML provides only basic validation attributes. Whereas, JavaScript allows for more dynamic and responsive validation that can improve user experience. But note that this isn’t by any means a security measure. &lt;/p&gt;

&lt;p&gt;However, it’s a much better approach to handling the form code and it can markedly improve user experience. For example, they won’t need to wait for the web page to refresh to see if the submission was successful. &lt;/p&gt;

&lt;p&gt;Now, to create a JavaScript-enhanced HTML email form that works seamlessly with various backend technologies (like Laravel, Java, Node.js, Python, and C#), I’ll focus on two main aspects: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Form validation &lt;/li&gt;
&lt;li&gt;AJAX submission
Check the following code to see how it’s done. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Form validation *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById('contact-form').addEventListener('submit', function(event) {
    var nameInput = document.getElementById('name').value.trim();
    var emailInput = document.getElementById('email').value.trim();
    var messageInput = document.getElementById('message').value.trim();
    var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email regex pattern

    if (nameInput === '') {
        alert('Please enter your name.');
        event.preventDefault();
    } else if (!emailPattern.test(emailInput)) {
        alert('Please enter a valid email address.');
        event.preventDefault();
    } else if (messageInput === '') {
        alert('Please enter your message.');
        event.preventDefault();
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pro Tip:&lt;/p&gt;

&lt;p&gt;The script above relies on a simple regex to validate an email, and it works for exemplary purposes. But on production, assuming you’re getting a lot of submissions, it may return false positives or false negatives, unless the regex is a mile long. &lt;/p&gt;

&lt;p&gt;To offset that, consider using a proper validation library such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AbstractAPI javascript-email-validation&lt;/li&gt;
&lt;li&gt;Yup&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Submitting form data with AJAX
&lt;/h3&gt;

&lt;p&gt;I made script below universal so that it dynamically adapts to the server-side technologies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById('contact-form').addEventListener('submit', function(event) {
    event.preventDefault();

    var formData = new FormData(this);
    var actionUrl = this.getAttribute('action'); // Dynamically get the action URL

    var xhr = new XMLHttpRequest();
    xhr.open('POST', actionUrl, true);
    xhr.onload = function () {
        if (xhr.status === 200) {
            alert('Email sent successfully!');
        } else {
            alert('An error occurred while sending the email.');
        }
    };
    xhr.send(formData);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick Notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Action URL: Instead of hardcoding the action URL (like &lt;code&gt;send-email.php&lt;/code&gt;), the script now dynamically retrieves the URL from the form’s &lt;code&gt;action&lt;/code&gt; attribute. This means you can set the action URL to any server-side script (PHP, Java, Node.js, etc.), and the JavaScript will adapt accordingly.&lt;/li&gt;
&lt;li&gt;Form Data: The &lt;code&gt;FormData&lt;/code&gt; object is used to capture and send all the form data, making it easy to handle on the server side, regardless of the technology used.&lt;/li&gt;
&lt;li&gt;Ensure that the endpoint (e.g., route in Laravel, or controller in ASP.NET) specified in the form’s &lt;code&gt;action&lt;/code&gt; attribute can handle &lt;code&gt;FormData&lt;/code&gt; sent via POST request.&lt;/li&gt;
&lt;li&gt;Each backend technology will have its way of extracting and processing the data, but the front-end submission process remains consistent and universal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Backed for HTML5 forms to send emails
&lt;/h2&gt;

&lt;p&gt;I’ll give you backend script examples in five popular scripting languages. Note that the exemplary scripts are geared toward Mailtrap users. &lt;/p&gt;

&lt;h3&gt;
  
  
  HTML form email in PHP (Laravel)
&lt;/h3&gt;

&lt;p&gt;The framework’s Mail class, combined with its view-based approach to email content, allows for easy and flexible email handling.&lt;/p&gt;

&lt;p&gt;Before you proceed with the backend, you need to make some changes to frontend HTML file.&lt;br&gt;
First create a view file, for example&lt;code&gt;/resources/views/welcome.blade.php&lt;/code&gt;. Then, ensure the specified route is matching this ‘welcome’ view.&lt;/p&gt;

&lt;p&gt;Note: Importing CSS and JS files parts are a little bit different from the original file. By default, these assets should be in the ‘public’ folder of your Laravel project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" &amp;gt;
&amp;lt;script src="{{ asset('js/app.js') }}" &amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set up Laravel for email sending&lt;/strong&gt;&lt;br&gt;
Before you can send emails with Laravel, you need to configure the mail settings in your &lt;code&gt;.env&lt;/code&gt;file. Laravel supports various mail drivers and here’s an example of setting up SMTP in the &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAIL_MAILER=smtp
MAIL_HOST=your_mailtrap_smtp_host.io
MAIL_PORT=2525
MAIL_USERNAME=your_mailtrap_username
MAIL_PASSWORD=your_mailtrap_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=example@example.com
MAIL_FROM_NAME="${APP_NAME}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the values with your Mailtrap mail server details. And if port 2525 doesn’t work for you, use 587. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a mailable class&lt;/strong&gt;&lt;br&gt;
Laravel uses “mailable” classes to encapsulate each email’s data and configuration. You can generate a new mailable class using the Artisan command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:mail ContactFormMail
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new class in the App\Mail namespace. You can define the build method to configure the email’s subject, view, and data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Queue\SerializesModels;


class ContactFormMail extends Mailable
{
    use Queueable, SerializesModels;

    public $formData;

    public function __construct($data)
    {
        $this-&amp;gt;formData = $data;
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'emails.contact',
        );
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create the email view&lt;/strong&gt;&lt;br&gt;
Create a view (e.g., &lt;code&gt;resources/views/emails/contact.blade.php&lt;/code&gt;) that Laravel will use for the email content. You can use Blade templating to dynamically populate data from the form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;New Contact Form Submission&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Contact Form Submission&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;Name: {{ $formData['name'] }}&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Email: {{ $formData['email'] }}&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt;Message: {{ $formData['message'] }}&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handle form submission in a controller&lt;/strong&gt;&lt;br&gt;
Important Note:&lt;/p&gt;

&lt;p&gt;The frontend may prevent the default event when submitting the email form and just send an API call to the backend server. In this case, the API URL is &lt;code&gt;/api/email&lt;/code&gt;. and the API request is handled in &lt;code&gt;routes/api.php&lt;/code&gt;. To fix this, add the following line in the &lt;code&gt;apip.php&lt;/code&gt; file. I omitted the ‘/api’ because of the structure of the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::post('/email', [EmailController::class, 'sendEmail']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the controller that handles the form submission, use the Mail facade to send the email:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Support\Facades\Mail;
use App\Mail\ContactFormMail;

public function sendEmail(Request $request)
{
    $formData = $request-&amp;gt;all();

    Mail::to('receiver@example.com')-&amp;gt;send(new ContactFormMail($formData));

    // Return response or redirect
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Security and validation&lt;/strong&gt;&lt;br&gt;
Ensure to validate and sanitize the form data to prevent security issues like XSS and injection attacks. Laravel provides a robust validation system that you can use in your controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;validate([
    'name' =&amp;gt; 'required',
    'email' =&amp;gt; 'required|email',
    'message' =&amp;gt; 'required'
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more detailed guid on &lt;a href="https://mailtrap.io/blog/html-email-form/"&gt;building HTML email form&lt;/a&gt;, please check our blog post in the link.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>php</category>
      <category>frontend</category>
      <category>backend</category>
    </item>
    <item>
      <title>Android Intent Send Email – Quick Tutorial with Examples</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Tue, 27 Feb 2024 16:50:10 +0000</pubDate>
      <link>https://forem.com/veljkoristic/android-intent-send-email-quick-tutorial-with-examples-4kl</link>
      <guid>https://forem.com/veljkoristic/android-intent-send-email-quick-tutorial-with-examples-4kl</guid>
      <description>&lt;p&gt;After tackling the Android Intent send email task, I have a newfound respect for this OS and its intricacies. The methodology is pretty straightforward and relatively simple to implement. &lt;/p&gt;

&lt;p&gt;I’ll cover the steps I took and show you how to use Intent to send emails from an Android app (code examples included). Plus, I dedicate a special section to error handling and email testing. &lt;/p&gt;

&lt;p&gt;Let’s start coding!&lt;/p&gt;

&lt;h2&gt;
  
  
  Android Intent send email
&lt;/h2&gt;

&lt;p&gt;The Intent method is the native way to send email in Android programmatically. &lt;/p&gt;

&lt;p&gt;So first, you need to make sure to have an Android project set up in your development environment. Here’s a quick overview of the steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Launch Android Studio&lt;/strong&gt; and select “Start a new Android Studio project”.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configure&lt;/strong&gt;: Project name, Save Location, Language (Java or Kotlin), and Minimum API Level (the minimum Android version supported by your project). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Select a template&lt;/strong&gt; – you can go with “Empty Activity” to get the basic UI. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hit “Finish”&lt;/strong&gt; and wait for the Studio to complete the setup. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Inspect the project structure&lt;/strong&gt; – with the setup complete, you’ll see a directory like app/src/main, and it includes:&lt;br&gt;
        – &lt;code&gt;java/&lt;/code&gt;: Your source code.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    – `res/`: Resources like layouts, strings, and images.

    – `AndroidManifest.xml`: Configuration file, where you can set the MainActivity.
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;To test the configuration&lt;/strong&gt;, hit the “Run” button (the green triangle). Then, choose a connected device or an emulator. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Pro Tips&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some emulators work well, but it’s best to have a genuine Android phone with the latest version of the software installed. Otherwise, emulators might throw unexpected errors. &lt;/li&gt;
&lt;li&gt;If you’re using an emulator, you’ll need to configure the email client. If the email client is not configured, it won’t respond to the Intent. &lt;/li&gt;
&lt;li&gt;To see a ‘chooser’ in action, you’ll need to configure a device using multiple messaging applications, for instance, use Gmail application and the Email application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, I’ll use &lt;code&gt;Intent&lt;/code&gt;to invoke an existing email client on the Android device. The &lt;code&gt;Intent&lt;/code&gt; has to be set up using the correct action: &lt;code&gt;ACTION_SEND&lt;/code&gt;or &lt;code&gt;ACTION_SENDTO&lt;/code&gt;. Also, you’ll need the correct data: email address, subject, body, etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I’m using Java in the examples below. This tutorial doesn’t cover SMS (optionally or otherwise), only an email message. &lt;/p&gt;

&lt;h3&gt;
  
  
  HTML email
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Intent&lt;/code&gt;system allows basic HTML via your Android application. Keep in mind that the final email rendering largely depends on the email client used by the recipient. (e.g. The rendering may look and perform differently on Gmail and Microsoft Outlook)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; You can run your email templates through Mailtrap Email Testing to check for support with the most popular email clients and debug the templates if necessary. I’ll show you how to do it at the end of this article. &lt;/p&gt;

&lt;p&gt;Here’s the exemplary snippet for the HTML email:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Method to send an HTML email to a single recipient without attachment
public void sendEmailSingleRecipient(String recipient, String subject, String htmlBody) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient}); // Single recipient
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

    // Adding HTML body
    emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmlBody));
    emailIntent.setType("text/html");

           startActivity(emailIntent);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method is tailored to a single email recipient, the recipient’s email address is passed a single-element array to the &lt;code&gt;Intent.EXTRA_EMAIL&lt;/code&gt; field. Later, I’ll show how to include BCC for multiple recipients. &lt;/p&gt;

&lt;p&gt;And with the &lt;code&gt;startActivity(emailIntent)&lt;/code&gt;; intent, any applications that support plaintext messaging will be able to handle this request. Once you have set the type data for the Intent, you can call the &lt;code&gt;startActivity()&lt;/code&gt; method, passing in your Intent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Email with attachment
&lt;/h3&gt;

&lt;p&gt;To include attachments you need to fetch the file from storage and add it as an extra stream to the intent. Check the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import necessary classes
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import java.io.File;


public class EmailSender extends AppCompatActivity {

public static final int PICK_TEXT_FILE_REQUEST = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button picker = findViewById(R.id.picker);
        picker.setOnClickListener(view -&amp;gt; {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("text/plain");
            startActivityForResult(Intent.createChooser(intent, "Select Text File"), PICK_TEXT_FILE_REQUEST);
        });
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PICK_TEXT_FILE_REQUEST &amp;amp;&amp;amp; resultCode == Activity.RESULT_OK) {
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    // Trigger file picker
                    sendEmailSingleRecipient("ghostdev030823@gmail.com",
                            "This is a test subject",
                            "This is a test email body using Android intent", uri);
                }
            }
        }
    }

    // Method to send an HTML email to a single recipient with an attachment
    public void sendEmailSingleRecipient(String recipient, String subject, String body, Uri filePath) {
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient});
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, body);
        emailIntent.putExtra(Intent.EXTRA_STREAM, filePath);
        emailIntent.setType("message/rfc822"); // only email apps should handle this

        startActivity(emailIntent);
}

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, remember to configure the &lt;code&gt;FileProvider&lt;/code&gt;in your Android manifest and resource files to handle file attachments securely.&lt;/p&gt;

&lt;p&gt;The correct configuration for the manifest file, particularly for the newer Android versions, is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;application&amp;gt;
    …
&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;
    &amp;lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&amp;gt;
    &amp;lt;uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /&amp;gt;
    &amp;lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&amp;gt;

    &amp;lt;provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true"&amp;gt;
            &amp;lt;meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/&amp;gt;
        &amp;lt;/provider&amp;gt;
    ...
&amp;lt;/application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the &lt;code&gt;res/xml/file_paths.xml&lt;/code&gt;, it’s:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;paths&amp;gt;
    &amp;lt;external-path name="external_files" path="."/&amp;gt;
&amp;lt;/paths&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Configuration notes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;your.authority&lt;/code&gt;with your app’s authority, typically your application’s package name.&lt;/li&gt;
&lt;li&gt;Ensure the file paths and permissions are correctly set for the &lt;code&gt;FileProvider&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Test the functionality with various email clients to check the HTML rendering and attachment handling (Gmail app, Apple Mail, etc.).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Send to multiple recipients
&lt;/h3&gt;

&lt;p&gt;For the sake of convenience, I’ll tweak the example above to include multiple recipients. Here’s the updated code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Import necessary classes
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import java.io.File;

public class EmailSender {

    // Method to send an HTML email to multiple recipients with an attachment
    public void sendEmailWithAttachment(String[] recipients, String subject, String htmlBody, File attachmentFile) {
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
        emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
        emailIntent.putExtra(Intent.EXTRA_EMAIL, recipients); // Multiple recipients
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

        // Check if the attachment is not null and exists
        if (attachmentFile != null &amp;amp;&amp;amp; attachmentFile.exists()) {
            // Add the attachment using FileProvider
            Uri uri = FileProvider.getUriForFile(context, "your.authority", attachmentFile);
            emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
        }

        // Adding HTML body
        emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmlBody));
        emailIntent.setType("text/html");

        // Verify that the intent will resolve to an activity
        if (emailIntent.resolveActivity(getPackageManager()) != null) {
            startActivity(Intent.createChooser(emailIntent, "Send email..."));
        } else {
            // Handle the situation where no email client is installed
            // Show an error message or a notification
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;recipients&lt;/code&gt; parameter is now an array of strings, allowing you to specify multiple email addresses. The rest of the method remains unchanged, supporting both HTML content and file attachments.&lt;/p&gt;

&lt;h3&gt;
  
  
  General guidelines on the Android Intent methodology
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Import statements&lt;/strong&gt;:I imported necessary classes like &lt;code&gt;Intent&lt;/code&gt;,&lt;code&gt;Uri&lt;/code&gt;, &lt;code&gt;File&lt;/code&gt;, and others.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sendEmail&lt;/code&gt; &lt;strong&gt;method&lt;/strong&gt;: This method accepts the recipients’ email addresses, the email subject, the HTML body, and an optional file attachment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Creating the Intent&lt;/strong&gt;: We use &lt;code&gt;Intent.ACTION_SENDTO&lt;/code&gt; with &lt;code&gt;mailto&lt;/code&gt;: to ensure only email apps handle this intent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adding recipients and subject&lt;/strong&gt;: I used &lt;code&gt;Intent.EXTRA_EMAIL&lt;/code&gt; and &lt;code&gt;Intent.EXTRA_SUBJECT&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handling attachment&lt;/strong&gt;: If an attachment is provided, I use a &lt;code&gt;FileProvider&lt;/code&gt; to get a content URI for the file and add it to the intent. This is a secure way to share files between apps starting from Android 7.0 (API level 24). As mentioned earlier, you’ll need to define a &lt;code&gt;FileProvider&lt;/code&gt; in your manifest and create an XML file defining available paths.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML body&lt;/strong&gt;:I used Html.fromHtml(htmlBody) to add the HTML formatted text to the email body. The rendering depends on the email client’s capabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intent type&lt;/strong&gt;: I set the type to "text/html", it can also be "text/plain". &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other considerations
&lt;/h2&gt;

&lt;p&gt;Here, I’d like to touch upon some functions, commands, and elements that didn’t make it into this tutorial. But, based on your specific use case, you might find them useful. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;EditText&lt;/strong&gt;: It’s a UI element in Android that allows users to enter text. It’s part of the Android SDK and is typically used within layout XML files to design the UI. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TextView&lt;/strong&gt;: This is another Android UI element that displays read-only text to the user. Unlike &lt;code&gt;EditText&lt;/code&gt;, &lt;code&gt;TextView&lt;/code&gt; doesn’t allow user input and is used primarily for displaying static text or text that changes dynamically&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OnClickListener&lt;/strong&gt;: It’s an Android interface that listens for click events on views such as buttons. By implementing the &lt;code&gt;OnClickListener&lt;/code&gt; interface and its &lt;code&gt;onClick&lt;/code&gt; method, you can define what happens when a user clicks on a particular view. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public void onClick&lt;/strong&gt;: It’s the declaration method for the &lt;code&gt;onClick&lt;/code&gt; method. When you implement the interface, you have to provide a corresponding implementation. It’s called when a view (with the listener attached) receives a click event.
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;To continue reading on Android Intent Send Email, check out the &lt;a href="https://mailtrap.io/blog/android-intent-send-email/"&gt;full article&lt;/a&gt; on Mailtrap blog.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>testing</category>
      <category>android</category>
    </item>
    <item>
      <title>How to Test Email: A Personal Journey</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Fri, 29 Dec 2023 18:50:18 +0000</pubDate>
      <link>https://forem.com/veljkoristic/how-to-test-email-a-personal-journey-3636</link>
      <guid>https://forem.com/veljkoristic/how-to-test-email-a-personal-journey-3636</guid>
      <description>&lt;p&gt;I’ve been with &lt;a href="https://mailtrap.io/"&gt;Mailtrap&lt;/a&gt; since 2021, and I have tested a gazillion emails (using Mailtrap) and talked to god-knows how many SMEs to wrap my mind around all the intricacies. &lt;/p&gt;

&lt;p&gt;This piece is an honest account of my ‘how to test email’ journey. It covers every aspect you can test, their importance, and the examples of best practices. &lt;/p&gt;

&lt;p&gt;Sure, I used Mailtrap almost exclusively, so the following sections feature a bunch of references and pointers to our platform. But, you’ll also encounter other tools and tips on how to incorporate them into your workflow. &lt;/p&gt;

&lt;h2&gt;
  
  
  What aspects of an email can you test?
&lt;/h2&gt;

&lt;p&gt;You can test ALL aspects of your email and here’s a quick list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Email deliverability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SPAM score&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Headers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Technical tests (DNS authentication, inbox placement, etc)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Email components and interaction elements&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also when testing, a structured approach is crucial, or you’ll get lost in all the data. Worse yet, you’ll waste a lot of time testing the wrong things. &lt;/p&gt;

&lt;h3&gt;
  
  
  Deliverability testing
&lt;/h3&gt;

&lt;p&gt;Deliverability testing is the first thing to do because it’s about making sure your emails hit the inbox, not the spam folder. And my dear colleague Piotr wrote a great guide on &lt;a href="https://mailtrap.io/blog/email-deliverability/"&gt;“Email deliverability: Everything you need to know”&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;We even got an entire cheatsheet playlist about it. Hit ▶️below. &lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.youtube.com/watch?list=PL9DaE1u2br9JjkFjw17mqJ8om0lQlBbRI&amp;amp;v=jy6YMzQZTz8&amp;amp;feature=youtu.be" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--VIu8ZYsy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.ytimg.com/vi/jy6YMzQZTz8/maxresdefault.jpg" height="450" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.youtube.com/watch?list=PL9DaE1u2br9JjkFjw17mqJ8om0lQlBbRI&amp;amp;v=jy6YMzQZTz8&amp;amp;feature=youtu.be" rel="noopener noreferrer" class="c-link"&gt;
          DKIM Explained - How It Works | Mailtrap - YouTube
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          This video offers a step by step explanation on how DKIM protocol works for email authentication.We answer the major questions concerning DKIM: what is DKIM,...
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--DOQSfsUf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.youtube.com/s/desktop/bcd251ee/img/favicon.ico" width="16" height="16"&gt;
        youtube.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Anyway, moving onto the nitty gritty of deliverability testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML check
&lt;/h3&gt;

&lt;p&gt;The HTML check is crucial in email content testing. Since this is not only about different content elements working but also about rendering. If the rendering is bad, the customer will think you are a spammer – spam complaint = sending reputation drop.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AveaJc6c3fI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Note that I’ll be covering &lt;a href="https://mailtrap.io/email-sandbox/"&gt;sandbox tests&lt;/a&gt; with Mailtrap to check emails before sending them. And that’s without spamming real recipients.  &lt;/p&gt;

&lt;p&gt;If you want to give &lt;a href="https://mailtrap.io/register/signup?ref=header"&gt;Mailtrap Email Testing&lt;/a&gt; a try, hit the button above ⬆️to sign up, then &lt;a href="https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing"&gt;follow this setup guide.&lt;/a&gt; You be testing your first email in minutes and there’s a free email testing plan. &lt;/p&gt;

&lt;p&gt;Later, I’ll talk about production email tests (with Mailtrap and otherwise). You can safely run these with a preselected cohort of your subscribers. For example, production email tests are A/B tests and specific aspects of trigger point tests like email heat maps. &lt;/p&gt;

&lt;p&gt;Finally, it’s time to move to WHATS and HOWS. &lt;/p&gt;

&lt;p&gt;The HTML check takes a deep dive into various elements (HTML and CSS) of your email template and assesses overall market support across different email clients, and different devices; covering web, mobile, and desktop. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qTdl-PHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1vmv237l4nn5yaf1y57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qTdl-PHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1vmv237l4nn5yaf1y57.png" alt="Image description" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s a neat “Only” button, which pops up when you hover left of each provider. Hitting it allows you to see the support for only the client you select. And if you’re dreading deliverability to Apple Mail, for example, it’s a cool trick to see how to fix your template so that Apple loves it. &lt;/p&gt;

&lt;p&gt;On that note, I’ll move on to show the other email template elements you can test under HTML Check.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Email body
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; element section shows you the support for the body of your email template. Note that this isn’t body copy of an email. It’s the HTML body of your email and how deliverable it is across different clients. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mFIVphO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwkiudhkwqe5vse3k0ss.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mFIVphO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwkiudhkwqe5vse3k0ss.png" alt="Image description" width="800" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, you can see that there’s partial support for the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; element and the problematic area is on line 6. When I click 6, next to “Found on lines:”, I’m taken to the HTML Source tab, and I can immediately see the problematic line, so it’s straightforward to fix it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XWrlx6Oq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pes72cdkgbk8g9asme88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XWrlx6Oq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pes72cdkgbk8g9asme88.png" alt="Image description" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, it seems the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; and the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; elements are in some conflict. So, I’m moving on to check that. &lt;/p&gt;

&lt;h3&gt;
  
  
  Styling and fonts
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; element section checks the support for template’s styling. I’m still using the same example, and as you can see below, some clients partially support the element, it appears buggy, and it’s not supported across all the email client versions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjblEb51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54q7s0n7ym5qwp38d70l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjblEb51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/54q7s0n7ym5qwp38d70l.png" alt="Image description" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, clicking on the number next to “Found on lines” takes me to the template and clearly shows what’s wrong. The best thing is that if a line gets declared as “Buggy”, there’s a quick explanation why it’s buggy and how to fix it, which may cut template debugging in half. &lt;/p&gt;

&lt;p&gt;As for the fonts, one of the key parameters Mailtrap checks is the font-weight. Of course, this is assuming you’re using a standard font family. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_EtxU50B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwupuoibmf9bg4myp5wa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_EtxU50B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwupuoibmf9bg4myp5wa.png" alt="Image description" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like before, the notes show you that the font-weight is partially supported, plus there’s a quick explanation of why it’s like that. But the check doesn’t stop there, you can also inspect the class selector, max-width, background-color, width property, max-width, and any other CSS or HTML element that might appear in the email. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ART94VxH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj4gbtfz5i9t4ee10dn6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ART94VxH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj4gbtfz5i9t4ee10dn6.png" alt="Image description" width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know, it may seem that there’s something seriously wrong with the template in the example, but it’s not. As you can see from the first screenshot, it has 93.8% support across different email clients. So it’s a good template, but there are options to make it even better. &lt;/p&gt;

&lt;p&gt;When you’re done checking the template, it’s time to see whether it has a chance to trigger spam bots. &lt;/p&gt;

&lt;h2&gt;
  
  
  SPAM score
&lt;/h2&gt;

&lt;p&gt;The spam testing results are under the Spam Analysis and they give you the overall score for an email. In the background, we’re running an up-to-date &lt;a href="https://mailtrap.io/blog/spamassassin-score/"&gt;SpamAssassin&lt;/a&gt; filter to determine the score. And you can see which elements of your template drive the score up. &lt;/p&gt;

&lt;p&gt;At the same time, under Blacklists Report, you’ll see if your domain and IP address appear in any of the most common blacklists. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_Xjy-W_s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vvoyqwhysw2i6arm79xr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Xjy-W_s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vvoyqwhysw2i6arm79xr.png" alt="Image description" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The template I’m using scored 3.3 which is okay. Generally, the recommendation is to keep the spam score under 5. But if you wanna get the score even higher, feel free to fix the rules as described in the table. &lt;/p&gt;

&lt;p&gt;If you need more info on how to steer clear of the spam folder, check our blog post on &lt;a href="https://mailtrap.io/blog/avoid-spam-filters/"&gt;“How to Avoid Emails Going to Spam?”. &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That out of the way, you can proceed to check the headers. &lt;/p&gt;

&lt;h2&gt;
  
  
  Email headers
&lt;/h2&gt;

&lt;p&gt;The Tech Info tab is the header information checker. You should know that it displays the original header values, which might be altered by an MTA or email service provider when sending the emails. However, the data we display are more than enough for debugging purposes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mm4VXAtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjfxjhslb30v8wb9ools.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mm4VXAtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjfxjhslb30v8wb9ools.png" alt="Image description" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, pointers to header information or buggy headers may also appear under the HTML Check tab, and the Spam Analysis tabs. For example, the Spam Analysis flags ‘Content-Type’ without the proper MIME header (check the screenshot below). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oQUEa2Ym--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bi6s2gz4extk86fwqbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oQUEa2Ym--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bi6s2gz4extk86fwqbj.png" alt="Image description" width="800" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation in Email Testing (via Mailtrap API)
&lt;/h2&gt;

&lt;p&gt;Yes, you can automate email testing and if you’re sending a lot of emails, you should consider doing it. Mailtrap allows you to automate via our &lt;a href="https://mailtrap.io/automated-email-testing/"&gt;RESTful API&lt;/a&gt; (available on the free pricing plan). &lt;/p&gt;

&lt;p&gt;Sure, it requires some coding but you can let the API run the dull tasks and notify you if there’s a problem. &lt;/p&gt;

&lt;p&gt;Since I mentioned Mailtrap HTML Check a few times, here’s an exemplary request script for the HTML analysis using PHP/cURL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL =&amp;gt; "https://mailtrap.io/api/accounts/account_id/inboxes/inbox_id/messages/message_id/analyze",
  CURLOPT_RETURNTRANSFER =&amp;gt; true,
  CURLOPT_ENCODING =&amp;gt; "",
  CURLOPT_MAXREDIRS =&amp;gt; 10,
  CURLOPT_TIMEOUT =&amp;gt; 30,
  CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST =&amp;gt; "GET",
  CURLOPT_HTTPHEADER =&amp;gt; [
    "Accept: application/json",
    "Api-Token: 123"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here’s an exemplary response to the request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "report": {
    "status": "success",
    "errors": [
      {
        "error_line": 15,
        "rule_name": "style",
        "email_clients": {
          "desktop": [
            "Notes 6 / 7"
          ],
          "mobile": [
            "Gmail"
          ]
        }
      },
      {
        "error_line": 7,
        "rule_name": "display",
        "email_clients": {
          "desktop": [
            "AOL Desktop",
            "IBM Notes 9",
            "Outlook 2000-03",
            "Outlook 2007-16",
            "Outlook Express",
            "Postbox",
            "Windows 10 Mail",
            "Windows Live Mail"
          ],
          "mobile": [
            "Android 4.2.2 Mail",
            "Android 4.4.4 Mail",
            "BlackBerry",
            "Gmail Android app IMAP",
            "Google Inbox Android app",
            "Windows Phone 8 Mail",
            "Yahoo! Mail Android app",
            "Yahoo! Mail iOS app"
          ],
          "web": [
            "Yahoo! Mail"
          ]
        }
      }
    ]
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response you’re looking for is 200. If there are any issues, the system will return 401, 404, or 404 error messages. &lt;/p&gt;

&lt;p&gt;Thank you for delving into this section of &lt;a href="https://mailtrap.io/blog/how-to-test-email/"&gt;Mailtrap's article.&lt;/a&gt; For a richer understanding, please visit the full article. We appreciate your engagement! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Salesforce Mass Email – How to Send and Test</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Tue, 26 Dec 2023 18:33:48 +0000</pubDate>
      <link>https://forem.com/veljkoristic/salesforce-mass-email-how-to-send-and-test-4bgj</link>
      <guid>https://forem.com/veljkoristic/salesforce-mass-email-how-to-send-and-test-4bgj</guid>
      <description>&lt;p&gt;Welcome to our comprehensive guide on Salesforce mass email sending. Whether you’re a tech-savvy professional or someone new to the platform, this article has got you covered. &lt;/p&gt;

&lt;p&gt;We’ll explore various methods and techniques to send mass emails using Salesforce. &lt;/p&gt;

&lt;p&gt;Read on to learn how to send targeted marketing campaigns or important updates to your customers. This article walks you through the process step by step and uncovers various methods and features available to help you reach a large audience effortlessly. &lt;/p&gt;

&lt;p&gt;Note: This article is for existing Salesforce users. It assumes that you’ve already set up Salesforce, so those steps won’t be covered. &lt;/p&gt;

&lt;h2&gt;
  
  
  Salesforce mass email limits
&lt;/h2&gt;

&lt;p&gt;Knowing your Salesforce limits helps secure a smooth and efficient emailing experience. Here are the highlights at the time of this writing. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Daily Mass Email Limit&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This limit is there to prevent abuse and maintain high deliverability. And it varies depending on your Salesforce edition and the number of user licenses. &lt;/p&gt;

&lt;p&gt;Note that the ‘daily mass email limit’ described here is the total maximal number of emails you can send per day, across all options and Editions. &lt;/p&gt;

&lt;p&gt;As per Salesforce Help Center, the limit is 5000 emails. And in Apex and API, the limitation is the same.&lt;/p&gt;

&lt;p&gt;Make sure to check your specific edition’s limit to ensure you stay within the allowed quota. Note that the highest mass email limit typically applies to the Enterprise Edition. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Recipient Limit:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Salesforce recipient limit also depends on your edition and the type of emails. For instance, for the six Editions of Salesforce, the recipient limit ranges from a few dozen to 5,000 recipients per mass email.&lt;/p&gt;

&lt;p&gt;To stress, the maximal number is again 5,000 but it pays to touch upon the concept so you can better understand the logic. &lt;/p&gt;

&lt;p&gt;For example, you could send one email to 5,000 recipients, thus exhausting your limit on the highest Editions. Or you could send multiple emails to specific recipient cohorts, to the same effect. For instance, 10 different emails to 500 recipients each. &lt;/p&gt;

&lt;p&gt;Either way, the cap is 5,000 on the highest plan, and you need to carefully plan your campaigns to avoid exhausting the limit too fast. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro Tip&lt;/strong&gt;: If the same external email address appears under different email marketing lists/campaigns, the address will be counted toward the limitation each time. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Size Limit&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each email you send has a maximum data size limit, which includes the combined size of the email content, attachments, and merged fields. The limit varies based on your Salesforce edition and ranges from a few MBs to 25 MB.&lt;/p&gt;

&lt;p&gt;The max limit is the same in Lightning Experience and Salesforce Classic, but there’s a difference in the number of attachments you can include. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Salesforce Classic – 10+ attachments, not exceeding 25MB&lt;/li&gt;
&lt;li&gt;Lightning Experience – up to 10 attachments, not exceeding 25MB &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Email Template Limitations&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Salesforce caps the number of templates at 500 for all organizations under Trial or Free plans. For more information on Salesforce platform limitations with paid editions, you’ll need to reach out to Salesforce support.&lt;/p&gt;

&lt;p&gt;Also, note that organizations using Developer Edition under a trial period can only send up to 10 emails to external email addresses. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus Tip: Deliverability Considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even though you can send mass emails with Salesforce integration, it’s crucial to maintain good deliverability and avoid practices that may result in your emails being marked as spam. If you want the details, check our blog post – “Email deliverability: everything you need to know”. &lt;/p&gt;

&lt;p&gt;Lastly, the limitations mentioned above could be subject to change, and it’s advisable to refer to the official Salesforce documentation for the most up-to-date information regarding mass email limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to send mass emails in Salesforce?
&lt;/h2&gt;

&lt;p&gt;Here, we’ll talk about sending mass emails in Salesforce Classic, so it’s more geared to legacy users (those who began using Salesforce prior to 2018 but still haven’t switched). However, we also cover Lightning Experience later in the article. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure to enable mass email with your Salesforce implementation. If that’s not done, you’re likely to get a message similar to the one below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile.: []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a mass mailing list of Contacts or Leads
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Navigate to Contacts or Leads&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click the &lt;strong&gt;Contacts&lt;/strong&gt; or &lt;strong&gt;Leads&lt;/strong&gt; tab, depending on the type of recipients you want to include in your mass email.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kNryZVNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rau8xslt2e6dyuk0k5js.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kNryZVNk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rau8xslt2e6dyuk0k5js.png" alt="Source: Salesforce support" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down to the &lt;strong&gt;Tools&lt;/strong&gt; section, and click &lt;strong&gt;Mass Email Contacts&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yQDBBYyL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6j97b52oxabp71nejcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yQDBBYyL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6j97b52oxabp71nejcx.png" alt="Source: Salesforce support" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Follow the Mass Email tool wizard&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After clicking &lt;strong&gt;Mass Email Contacts&lt;/strong&gt;, you enter a four-step process to set up and customize your mass email campaigns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lM0R3jQB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28h415qdii4onerwas07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lM0R3jQB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28h415qdii4onerwas07.png" alt="Source: Salesforce support&amp;lt;br&amp;gt;
" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, you need to choose the recipients for the campaign. Then, choose a &lt;strong&gt;View&lt;/strong&gt; from the drop-down menu, or click &lt;strong&gt;Create New View&lt;/strong&gt;. For the purposes of this tutorial, we’ll choose the latter. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bw6VPWDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlgi5mxooo2shj852e66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bw6VPWDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlgi5mxooo2shj852e66.png" alt="Source: Salesforce support" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, add the View name, and use filters, such as specific fields, campaign membership, or custom criteria, to narrow down your target audience.&lt;/p&gt;

&lt;p&gt;Make sure to leverage specific Salesforce customization options and select filters and criteria only for the mass email leads you’d like to contact. &lt;/p&gt;

&lt;p&gt;Salesforce offers quite a few filtration options and allows you to choose fields to display and filter by specific fields. That allows you to create a mass email list, zeroing in only on the user cohort you wish to contact. &lt;/p&gt;

&lt;p&gt;Also, you can change the visibility of your campaign under Step 4.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CnVCUj-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wegger3z40ehwm8av77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CnVCUj-1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wegger3z40ehwm8av77.png" alt="Source: Salesforce support" width="800" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Save the Mailing List&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you have defined your criteria, save the mailing list. Upon clicking the button, you’ll see the filtered list of recipients. You can add or remove recipients by checking or unchecking the box in front of their names. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8DFgrlCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/777mwec9h0tlnajpeqjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8DFgrlCH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/777mwec9h0tlnajpeqjz.png" alt="Source: Salesforce support" width="800" height="1373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder:&lt;/strong&gt; The number of recipients per single email varies based on the Salesforce edition you use. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Choose an email template&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After saving the list, you move to Step 2 of Mass Email with Salesforce. Here, you choose the email template. Keep in mind that you can’t create a new template at this step. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y49tJBDx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/roj14zjbd13xpkyv7n4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y49tJBDx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/roj14zjbd13xpkyv7n4v.png" alt="Source: Salesforce support" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Confirm your choice and send&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 3 gives you the option to BCC an email copy to yourself, you can create a custom Mass Email Name, and send it immediately, or schedule the campaign. &lt;/p&gt;

&lt;p&gt;A scheduled email has a “pending” status until sent, and you can cancel it anytime prior to the due date/time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TwaY57Na--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gexqttoywxn7gm39as3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TwaY57Na--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gexqttoywxn7gm39as3o.png" alt="Source: Salesforce support" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should you choose to hit the Send button, your email gets sent immediately, and you’ll get the confirmation window. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ayVSX-fR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1472htrvyt5xh0wzff5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ayVSX-fR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1472htrvyt5xh0wzff5.png" alt="Source: Salesforce support" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Check status and manage&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To see the status of your emails and manage campaigns, you need to do the following. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click your account name in the upper right section and choose &lt;strong&gt;My Settings&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Select Email in the side menu, then click &lt;strong&gt;Mass Email&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_7Lf72rC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb0m8rrs1k77t50iad9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_7Lf72rC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb0m8rrs1k77t50iad9k.png" alt="Source: Salesforce support" width="800" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Check the list of all your campaigns per the selected &lt;strong&gt;View&lt;/strong&gt;.  This is also where you can cancel pending campaigns. &lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Sending bulk emails in Lightning Experience
&lt;/h2&gt;

&lt;p&gt;Overall, the processes and functionalities are mostly consistent across Salesforce Classic and its revamped sibling. Though, we should stress that Salesforce Lightning is more feature-rich, particularly in the area of data management, analytics, and marketing automation. And sending bulk emails in Lightning Experience is faster and more user-friendly.&lt;/p&gt;

&lt;p&gt;However, we won’t focus on features comparison here. Instead, we’ll show you the most effective way to send mass emails and highlight any significant differences, if necessary. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create an email template&lt;/strong&gt;
Click the &lt;strong&gt;App Launcher&lt;/strong&gt; (nine colorful dots) in the upper left corner of the screen, type ‘Email Templates’, and hit enter. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gfY8D8yX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89ypqxdqozez68qjad2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gfY8D8yX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89ypqxdqozez68qjad2r.png" alt="Source: Salesforce Support YouTube" width="800" height="773"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;strong&gt;New Email Template&lt;/strong&gt; button, and create your template. Make sure to include the subject, message body, and any merge fields or templates you wish to utilize, then &lt;strong&gt;Save&lt;/strong&gt; it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--01zY1FYi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oix6fj2n8akxp5e8s113.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--01zY1FYi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oix6fj2n8akxp5e8s113.png" alt="Source: Salesforce Support YouTube" width="800" height="695"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You don’t have to start by creating a template, you can do it later, or select one of the existing templates. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Navigate to Send List Email&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In &lt;strong&gt;Lightning Experience&lt;/strong&gt;, the feature is actually called &lt;strong&gt;Send List Email&lt;/strong&gt;, instead of  &lt;strong&gt;Mass Email&lt;/strong&gt;. And it appears under the &lt;strong&gt;Contacts&lt;/strong&gt;, &lt;strong&gt;Leads&lt;/strong&gt;, or &lt;strong&gt;Campaign Member&lt;/strong&gt; view. And the steps are largely the same regardless of the method you choose. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gu-vzJ3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avuo583zg3cu989bhyxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gu-vzJ3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avuo583zg3cu989bhyxz.png" alt="Source: Salesforce Support YouTube" width="800" height="125"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Send List Email&lt;/strong&gt; and, under &lt;strong&gt;New List View&lt;/strong&gt;, type &lt;strong&gt;List Name&lt;/strong&gt; and &lt;strong&gt;List API Name&lt;/strong&gt; into the designated fields. Then, choose ‘view permissions’ and click &lt;strong&gt;Save&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DctJNx2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfcfm50wm8435hegpn6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DctJNx2R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfcfm50wm8435hegpn6g.png" alt="Source: Salesforce Support YouTube" width="800" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Select the Recipients&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hover over the &lt;strong&gt;Filter by Owner&lt;/strong&gt; box and choose the contacts to send bulk email to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BG7ngqVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0zouw91e5i09wqrvnay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BG7ngqVi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0zouw91e5i09wqrvnay.png" alt="Source: Salesforce Support YouTube" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Proceed to &lt;strong&gt;Add Filter&lt;/strong&gt; and segment your recipients based on the given &lt;strong&gt;Field&lt;/strong&gt;, &lt;strong&gt;Operator&lt;/strong&gt;, and &lt;strong&gt;Value&lt;/strong&gt; criteria.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSSUpSrD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzcxgew78c2w8cdlxe2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSSUpSrD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzcxgew78c2w8cdlxe2b.png" alt="Source: Salesforce Support YouTube" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Depending on your requirements, you can opt to send the email to specific campaign members, contacts, or leads from a report, or custom lists. Plus, you can use the &lt;strong&gt;Add Filter Logic&lt;/strong&gt; option to give your list another dimension. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Review and Send&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before sending the email, take a moment to review the recipient list, email content, and any attached files. Ensure everything is accurate and aligns with your intended communication. &lt;/p&gt;

&lt;p&gt;Afterward, click the &lt;strong&gt;Send List Email&lt;/strong&gt; button, then the &lt;strong&gt;Insert&lt;/strong&gt;, &lt;strong&gt;create&lt;/strong&gt;, &lt;strong&gt;or update template&lt;/strong&gt; icon. Insert the template you created in the first step; here you can also add merged fields by clicking on the ‘braces’ icon. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1VOmZlgf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifo4kl4ei0zqpumsmxx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1VOmZlgf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifo4kl4ei0zqpumsmxx5.png" alt="Source: Salesforce Support YouTube" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you confirm all’s well and you’re sending to the right recipients, hit &lt;strong&gt;Send&lt;/strong&gt;, and your campaign will be deployed. &lt;/p&gt;
&lt;h2&gt;
  
  
  How to send mass email through Batch Apex in Salesforce
&lt;/h2&gt;

&lt;p&gt;In addition to the built-in Mass Email or Send List Email functionality, Salesforce provides Apex, a versatile object-oriented language, similar to Java. &lt;/p&gt;

&lt;p&gt;By leveraging Apex, you can automate the process of sending bulk emails, enabling you to handle larger volumes of email communications. &lt;/p&gt;

&lt;p&gt;Let’s explore how you can send mass emails through Apex in Salesforce.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Import statements and create an Apex class&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Begin by importing statements and creating an Apex class that implements the ‘Batchable’ interface. This class will define the logic and behavior for sending the mass email.&lt;/p&gt;

&lt;p&gt;Here are the import statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Database;
import Messaging;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Importing &lt;code&gt;Database&lt;/code&gt; and &lt;code&gt;Messaging&lt;/code&gt; is optional. &lt;/p&gt;

&lt;p&gt;And you define the class using the following line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MassEmailBatch implements Database.Batchable&amp;lt;sObject&amp;gt; {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This declares a class named &lt;code&gt;MassEmailBatch&lt;/code&gt; that implements the &lt;code&gt;Database.Batchable&amp;lt;sObject&amp;gt;&lt;/code&gt; interface. It signifies that this class can be used as a batch job for processing records.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Implement the Start, Execute, and Finish Methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the Apex class, implement the Start method, which retrieves the collection of records to process (your recipients, in this particular case). This can be based on criteria or queries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Database.QueryLocator start(Database.BatchableContext context) {
    String query = 'SELECT Email, Name FROM Contact WHERE Email IN (\'fd547125b4-5ea78e@inbox.mailtrap.io\')'; //SELECT Id, Email, Name FROM Contact WHERE &amp;lt;your_criteria_here&amp;gt;
    return Database.getQueryLocator(query);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stress, the start method is required for a batch job and specifies the initial step of the batch process. It returns a &lt;code&gt;Database.QueryLocator&lt;/code&gt; object that defines the records to be processed. &lt;/p&gt;

&lt;p&gt;In this case, the method queries the Contact records based on specific criteria and returns a query locator for those records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reminder:&lt;/strong&gt; Don’t forget to specify the criteria under &lt;code&gt;&amp;lt;your_criteria_here&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That out of the way, you can implement the Execute method, where the script iterates through the collection of records and constructs personalized email messages using Apex Email Messaging classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void execute(Database.BatchableContext context, List&amp;lt;sObject&amp;gt; scope) {
    List&amp;lt;Messaging.SingleEmailMessage&amp;gt; emails = new List&amp;lt;Messaging.SingleEmailMessage&amp;gt;();

    for (sObject record : scope) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setSubject('Your Subject Here');
        email.setPlainTextBody('Hello,\n' + String.valueOf(record.get('Name')));
        email.setToAddresses(new String[] { (String) record.get('Email') });

        emails.add(email);
    }

    Messaging.SendEmailResult[] results = Messaging.sendEmail(emails);

    for (Messaging.SendEmailResult result : results) {
        if (result.isSuccess()) {
            // Email sent successfully
            System.debug('Email sent successfully');
        } else {
            // Handle any errors or exceptions
            System.debug('Error sending email: ' + result.getErrors()[0].getMessage());
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where the actual record processing takes place. The script receives a batch of records (a scope) to process. In our example, it iterates through each record and constructs a personalized email message using the &lt;code&gt;Messaging.SingleEmailMessage&lt;/code&gt; class. &lt;/p&gt;

&lt;p&gt;The script then sets the email subject, plain text body, and recipient’s email address based on the record’s data.&lt;/p&gt;

&lt;p&gt;The constructed email messages are added to the email list. After all the records are processed, the &lt;code&gt;Messaging.sendEmail&lt;/code&gt; method is used to send the batch of email messages. The &lt;code&gt;Messaging.SendEmailResult&lt;/code&gt; array contains the results of the email-sending operation, which are then processed to check for any errors or exceptions.&lt;/p&gt;

&lt;p&gt;Lastly, you’ll need to implement the Finish method, which handles any necessary cleanup tasks or post-processing actions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void finish(Database.BatchableContext context) {
    // Perform any necessary cleanup tasks or post-processing actions
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For your reference, here’s the full script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Database;
import Messaging;

public class MassEmailBatch implements Database.Batchable&amp;lt;sObject&amp;gt; {

    public Database.QueryLocator start(Database.BatchableContext context) {
        // Retrieve the collection of records to process based on specific criteria or queries
        String query = 'SELECT Email, Name FROM Contact WHERE Email IN (\'fd547125b4-5ea78e@inbox.mailtrap.io\')'; //SELECT Id, Email, Name FROM Contact WHERE &amp;lt;your_criteria_here&amp;gt;
        return Database.getQueryLocator(query);
    }

    public void execute(Database.BatchableContext context, List&amp;lt;sObject&amp;gt; scope) {
        List&amp;lt;Messaging.SingleEmailMessage&amp;gt; emails = new List&amp;lt;Messaging.SingleEmailMessage&amp;gt;();

        // Iterate through the collection of records and construct personalized email messages
        for (sObject record : scope) {
            // Construct the email message using Apex Email Messaging classes
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setSubject('Your Subject Here');
            email.setPlainTextBody('Hello, ' + String.valueOf(record.get('Name')));
            email.setToAddresses(new String[] { (String) record.get('Email') });

            emails.add(email);
        }

        // Send the batch of email messages
        Messaging.SendEmailResult[] results = Messaging.sendEmail(emails);

        // Process the results if needed
        for (Messaging.SendEmailResult result : results) {
            if (result.isSuccess()) {
                // Email sent successfully
                System.debug('Email sent successfully');
            } else {
                // Handle any errors or exceptions
                System.debug('Error sending email: ' + result.getErrors()[0].getMessage());
            }
        }
    }

    public void finish(Database.BatchableContext context) {
        // Perform any necessary cleanup tasks or post-processing actions
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Send with email template&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Create and customize the template according to your needs and include any merge fields as required. You can do all that within the Salesforce interface, but make sure to save the template ID to reference it in the code.  &lt;/p&gt;

&lt;p&gt;Now, we’d need to rework the ‘execute’ method so it references a template, here’s the snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MassEmailBatchWithTemplate implements Database.Batchable&amp;lt;sObject&amp;gt; {

    public static final String EMAIL_TEMPLATE_NAME = 'MyTemplate';

    public Database.QueryLocator start(Database.BatchableContext context) {
        // Retrieve the collection of records to process based on specific criteria or queries
        String query = 'SELECT Email, Name FROM Contact WHERE Email IN (\'fd547125b4-5ea78e@inbox.mailtrap.io\')'; //SELECT Id, Email, Name FROM Contact WHERE &amp;lt;your_criteria_here&amp;gt;
        return Database.getQueryLocator(query);
    }

    public void execute(Database.BatchableContext context, List&amp;lt;sObject&amp;gt; scope) {
        List&amp;lt;Messaging.SingleEmailMessage&amp;gt; emails = new List&amp;lt;Messaging.SingleEmailMessage&amp;gt;();

        // Get the email template
        EmailTemplate emailTemplate = [
            SELECT Id, Subject, Body, HtmlValue
            FROM EmailTemplate
            WHERE Name = :EMAIL_TEMPLATE_NAME
            LIMIT 1
        ];

        // Iterate through the collection of records and construct personalized email messages
        for (sObject record : scope) {
            // Construct the email message using Apex Email Messaging classes
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

            // Set the email template ID
            email.setTemplateId(emailTemplate.Id);
            // Set the email template Subject
            email.setSubject(emailTemplate.Subject);
            // Set the email html Body
            email.setHtmlBody(emailTemplate.HtmlValue);
            email.setToAddresses(new String[] { (String) record.get('Email') });

            // Set the target object ID
            email.setTargetObjectId((Id) record.get('Id'));

            emails.add(email);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what we did:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Added the line &lt;code&gt;email.setTemplateId('&amp;lt;your_template_id_here&amp;gt;');&lt;/code&gt; to set the ID of the email template you want to use. Replace &lt;code&gt;&amp;lt;your_template_id_here&amp;gt;&lt;/code&gt; with the actual ID of your email template.&lt;/li&gt;
&lt;li&gt;Added the line 
&lt;code&gt;email.setTargetObjectId((Id) record.get('Id'));&lt;/code&gt; to set the ID of the recipient object. This can be the ID of the contact, lead, or user to whom you want to send the email.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check the full reworked script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Database;
import Messaging;

public class MassEmailBatchWithTemplate implements Database.Batchable&amp;lt;sObject&amp;gt; {

    public static final String EMAIL_TEMPLATE_NAME = 'MyTemplate';

    public Database.QueryLocator start(Database.BatchableContext context) {
        // Retrieve the collection of records to process based on specific criteria or queries
        String query = 'SELECT Email, Name FROM Contact WHERE Email IN (\'fd547125b4-5ea78e@inbox.mailtrap.io\')'; //SELECT Id, Email, Name FROM Contact WHERE &amp;lt;your_criteria_here&amp;gt;
        return Database.getQueryLocator(query);
    }

    public void execute(Database.BatchableContext context, List&amp;lt;sObject&amp;gt; scope) {
        List&amp;lt;Messaging.SingleEmailMessage&amp;gt; emails = new List&amp;lt;Messaging.SingleEmailMessage&amp;gt;();

        // Get the email template
        EmailTemplate emailTemplate = [
            SELECT Id, Subject, Body, HtmlValue
            FROM EmailTemplate
            WHERE Name = :EMAIL_TEMPLATE_NAME
            LIMIT 1
        ];

        // Iterate through the collection of records and construct personalized email messages
        for (sObject record : scope) {
            // Construct the email message using Apex Email Messaging classes
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

            // Set the email template ID
            email.setTemplateId(emailTemplate.Id);
            // Set the email template Subject
            email.setSubject(emailTemplate.Subject);
            // Set the email HTML Body
            email.setHtmlBody(emailTemplate.HtmlValue);
            email.setToAddresses(new String[] { (String) record.get('Email') });

            // Set the target object ID
            email.setTargetObjectId((Id) record.get('Id'));

            emails.add(email);
        }

        // Send the batch of email messages
        Messaging.SendEmailResult[] results = Messaging.sendEmail(emails);

        // Process the results if needed
        for (Messaging.SendEmailResult result : results) {
            if (result.isSuccess()) {
                // Email sent successfully
                System.debug('Email sent successfully');
            } else {
                // Handle any errors or exceptions
                System.debug('Error sending email: ' + result.getErrors()[0].getMessage());
            }
        }
    }

    public void finish(Database.BatchableContext context) {
        // Perform any necessary cleanup tasks or post-processing actions
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Schedule and execute an Apex batch&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To schedule and execute a batch, and then send mass email from custom object, we’ll need to go back to the script above and add yet another layer of functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Database;
import Messaging;
import System;

public class MassEmailBatch implements Database.Batchable&amp;lt;sObject&amp;gt;, Database.AllowsCallouts, Schedulable {

    public Database.QueryLocator start(Database.BatchableContext context) {
        // Retrieve the collection of records to process based on specific criteria or queries
        String query = 'SELECT Email, Name FROM Contact WHERE Email IN (\'fd547125b4-5ea78e@inbox.mailtrap.io\')'; //SELECT Id, Email, Name FROM Contact WHERE &amp;lt;your_criteria_here&amp;gt;
        return Database.getQueryLocator(query);
    }

    public void execute(Database.BatchableContext context, List&amp;lt;sObject&amp;gt; scope) {
        List&amp;lt;Messaging.SingleEmailMessage&amp;gt; emails = new List&amp;lt;Messaging.SingleEmailMessage&amp;gt;();

        // Get the email template
        EmailTemplate emailTemplate = [
            SELECT Id, Subject, Body, HtmlValue
            FROM EmailTemplate
            WHERE Name = :EMAIL_TEMPLATE_NAME
            LIMIT 1
        ];

        // Iterate through the collection of records and construct personalized email messages
        for (sObject record : scope) {
            // Construct the email message using Apex Email Messaging classes
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

            // Set the email template ID
            email.setTemplateId(emailTemplate.Id);
            // Set the email template Subject
            email.setSubject(emailTemplate.Subject);
            // Set the email HTML Body
            email.setHtmlBody(emailTemplate.HtmlValue);
            email.setToAddresses(new String[] { (String) record.get('Email') });

            // Set the target object ID
            email.setTargetObjectId((Id) record.get('Id'));

            emails.add(email);
        }

        // Send the batch of email messages
        Messaging.SendEmailResult[] results = Messaging.sendEmail(emails);

        // Process the results if needed
        for (Messaging.SendEmailResult result : results) {
            if (result.isSuccess()) {
                // Email sent successfully
                System.debug('Email sent successfully');
            } else {
                // Handle any errors or exceptions
                System.debug('Error sending email: ' + result.getErrors()[0].getMessage());
            }
        }
    }

    public void execute(SchedulableContext context) {
        // Create an instance of the batch class
        MassEmailBatch batch = new MassEmailBatch();

        // Schedule the batch job
        Database.executeBatch(batch);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these additions, the class now implements the ‘Schedulable’ interface, allowing you to schedule and execute the batch job using the Salesforce scheduler. The &lt;code&gt;execute()&lt;/code&gt; method from the ‘Schedulable’ interface is implemented, where you create an instance of the batch class and call &lt;code&gt;Database.executeBatch()&lt;/code&gt; to schedule the batch job.&lt;/p&gt;

&lt;p&gt;Thereon, you can use the &lt;code&gt;System.schedule()&lt;/code&gt; method in Salesforce to schedule the execution of the MassEmailBatch class based on your desired schedule. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String scheduleExpression = '0 0 0 1 1 ? 2024'; // Schedule for January 1, 2024
MassEmailBatch scheduler = new MassEmailBatch();
System.schedule('Mass Email Job', scheduleExpression, scheduler);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, &lt;code&gt;the MassEmailBatch&lt;/code&gt; class is scheduled to run on January 1, 2024. You can modify the &lt;code&gt;scheduleExpression&lt;/code&gt; to define your desired schedule.&lt;/p&gt;

&lt;p&gt;Make sure to adjust the schedule expression and any other parameters to fit your specific requirements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Monitor the Progress and Results&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep an eye on the progress of the Batch Apex job by reviewing the Apex job queue or monitoring logs.&lt;/p&gt;

&lt;p&gt;Once the job completes, analyze the results and track any errors or exceptions for troubleshooting purposes.&lt;/p&gt;

&lt;p&gt;Remember to ensure that your Apex implementation adheres to Salesforce’s best practices, follows email regulations and permissions, and respects the privacy and preferences of your recipients.&lt;/p&gt;

&lt;p&gt;And if you need more information on sending emails using Apex, check our “&lt;a href="https://mailtrap.io/blog/apex-send-email/"&gt;In-Depth Gide on Sending Emails With Apex&lt;/a&gt;”. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to test emails before sending them?
&lt;/h2&gt;

&lt;p&gt;There are two options to test emails in Salesforce – use &lt;a href="https://mailtrap.io/blog/apex-send-email/#:~:text=those%2C%20shall%20we%3F-,Apex%20test%20class,-The%20Apex%20test"&gt;Apex test class&lt;/a&gt;, which we cover in a separate article. Or you could use a third-party tool such as Mailtrap. &lt;/p&gt;

&lt;p&gt;But why third-party tools when there’s an Apex test class? &lt;/p&gt;

&lt;p&gt;Well, the Apex class test results are one-dimensional, and only check the code functionality. But besides testing the functionality, you’ll also want to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Determine how much different mailbox providers support your HTML and CSS templates. &lt;/li&gt;
&lt;li&gt;Check the spam score in sandbox. &lt;/li&gt;
&lt;li&gt;Debug an email notification in staging without risking your sender’s reputation. &lt;/li&gt;
&lt;li&gt;Fully automate test flows and scenarios.
Minimize the chance to experience a lot of bounces. &lt;/li&gt;
&lt;li&gt;Without much further ado, we’ll jump right into the methods. And note that we assume that you already have a Mailtrap account. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: You don’t have to add and verify a domain to test emails. This doesn’t apply to Mailtrap Email Sending.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://mailtrap.io/smtp-service/"&gt;SMTP&lt;/a&gt; Method
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Get your Mailtrap SMTP credentials&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once inside Mailtrap, click &lt;strong&gt;Email Testing&lt;/strong&gt; in the menu on the left, then the inbox you’d like to use under &lt;strong&gt;Inboxes&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--khTk48eR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ylntvpge5sqjxgl4ori.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--khTk48eR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ylntvpge5sqjxgl4ori.png" alt="Image description" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under SMTP settings click “Show Credentials” to reveal them. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JB0yNdzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8ym7fpjdpfc3x3z91bw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JB0yNdzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8ym7fpjdpfc3x3z91bw.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Configure an email relay&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Navigate to the Email Relays menu by typing ‘relays’ into the search box. Generally, the Email Relays menu is under Setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--82D31MaH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzzvfryglpl0qb4zdcdu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--82D31MaH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzzvfryglpl0qb4zdcdu.png" alt="Source: Salesforce Support YouTube" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, click the Create Email Relay button, and copy-paste the credentials provided by Mailtrap. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CbeSmsiR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajrc5r81ewphsj9z6t9x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CbeSmsiR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajrc5r81ewphsj9z6t9x.png" alt="Source: Salesforce Support YouTube" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to tick the box next to &lt;strong&gt;Enable SMTP Auth&lt;/strong&gt;, and use the credentials provided by Mailtrap. Also, keep the box next to &lt;strong&gt;Change Password&lt;/strong&gt; unchecked. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save and set up filters&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click the Save button, but note that your relay still isn’t active. Under Email Relays, click the “&lt;strong&gt;filters for recipients and sender domains&lt;/strong&gt;” link. Then, proceed to create a fliter. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P9u2NiCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9c9yg463e32qqcobgmzu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P9u2NiCD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9c9yg463e32qqcobgmzu.png" alt="Source: Salesforce Support YouTube" width="800" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Email Domain Filters configuration&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Upon creating a filter, the default configuration is to send emails to all user domains from all sender domains. Of course, for testing purposes, you should choose the Mailtrap Testing SMTP relay, you just created from the Email Relay dropdown. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IgpEzDLm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5ht6h4my5aumz13oqzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IgpEzDLm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5ht6h4my5aumz13oqzm.png" alt="Source: Salesforce Support YouTube" width="800" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save the filter, and proceed to use the flowing script to send test emails.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ApexEmailSample {
    public static void sendEmail(String useremail){      
    Messaging.reserveSingleEmailCapacity(20);
        Messaging.SingleEmailMessage mymail = new Messaging.SingleEmailMessage();
        String[] toaddresses = new String[] {useremail};
        String[] toccaddresses = new String[] {'som****@gmail.com'};
        String[] tobccaddresses = new String[] {'ez*****@gmail.com'};

        mymail.setToAddresses(toaddresses);
        mymail.setCcAddresses(toccaddresses);
        mymail.setBccAddresses(tobccaddresses);
        mymail.setReplyTo('support@example.com');
        mymail.setSenderDisplayName('Salesforce Support');
        mymail.setSubject('An email from Salesforce');
        mymail.setPlainTextBody('This email has been sent through Apex');
        mymail.setHtmlBody('&amp;lt;p&amp;gt;This email has been sent through Apex.&amp;lt;/p&amp;gt;');

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mymail });
    system.debug(useremail);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this is only one of the ways you can test Salesforce emails with Mailtrap. If you want to dive deeper into all available methods and workflows, check our comprehensive guide on “&lt;a href="https://mailtrap.io/blog/salesforce-test-emails/"&gt;How to Test Emails in Salesforce with Mailtrap Email Testing&lt;/a&gt;”. &lt;/p&gt;

&lt;h2&gt;
  
  
  Sending with 3rd party email providers: why and how?
&lt;/h2&gt;

&lt;p&gt;As we already covered sending emails natively with Salesforce, this section focuses on third-party email providers. We cover the reasons to use third-party providers, as well as some downsides to keep in mind. &lt;/p&gt;

&lt;p&gt;Also, the exemplary integration is geared toward Mailtrap users. For now, you’ll only be able to send transactional emails – our bulk email feature is currently under development. &lt;/p&gt;

&lt;p&gt;Be that as it may, Mailtrap and Salesforce make a killer marketing tool. They allow you to seamlessly merge the CRM and email solutions and take the sales in your company to the next level. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Whys
&lt;/h3&gt;

&lt;p&gt;When it comes to sending emails from Salesforce, you have a couple of options. You can use Salesforce’s built-in email services, or you can use a third-party email service provider. &lt;/p&gt;

&lt;p&gt;While Salesforce’s built-in services are convenient, there are several compelling reasons to consider using a third-party service:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deliverability&lt;/strong&gt;: Third-party email service providers such as Mailtrap specialize in email deliverability. They have dedicated teams and technologies to ensure your emails reach the recipient’s inbox and not their spam folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: If you’re sending at a volume, third-party services are designed to handle and &lt;a href="https://mailtrap.io/blog/actionmailer-balancer/"&gt;balance that load&lt;/a&gt;. Salesforce has daily limits on the number of emails you can send, which can be a constraint for some businesses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features&lt;/strong&gt;: Third-party services often come with additional features such as email templates, analytics, A/B testing, automation, and more. These can be valuable tools for optimizing your email campaigns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost-effectiveness&lt;/strong&gt;: Depending on your volume of emails and the specific features you need, third-party services can often be a more cost-effective solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, there are also some potential downsides to consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Integration&lt;/strong&gt;: You’ll need to integrate the third-party service with Salesforce, which can require some technical setup. But at Mailtrap, we ensured the integration process is as smooth as possible. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency&lt;/strong&gt;: You’re relying on another service, which could potentially have its own downtime or issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost&lt;/strong&gt;: While often cost-effective, there is still a cost associated with third-party services. You’ll need to evaluate this against your budget and needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The How
&lt;/h3&gt;

&lt;p&gt;As a reminder, the quick tutorial below is geared toward transactional emails that you can send at scale with Mailtrap. &lt;/p&gt;

&lt;p&gt;Also, unlike Mailtrap Testing, Mailtrap Sending requires you to add and verify a domain. And, in the sections below, we assume you already did it.  &lt;/p&gt;

&lt;p&gt;If you need any help adding or verifying your domain, check our Getting Started Guide. Or watch our Domain Setup Video. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Add Email Relay&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To start sending transactional emails via Mailtrap Sending, you need to set up another Email Relay. The steps are pretty much the same as previously described under the Testing tutorial. So, we won’t go into details here, only pay attention to the number of relays you can add as per your Salesforce Edition. &lt;/p&gt;

&lt;p&gt;Also, keep in mind that, of course, we have somewhat different credentials for Testing and Sending. Take the following path to get to them. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending Domains &amp;gt; Choose a domain &amp;gt; SMTP/API Settings&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ye0ILcfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5oyvspzormo5b5taz4t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ye0ILcfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5oyvspzormo5b5taz4t.png" alt="Image description" width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Send test email&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To stress, the ‘test email’ you’ll be sending is there to confirm your configuration. By default, the ‘test email’ gets sent to the email address you use to sing into Mailtrap. &lt;/p&gt;

&lt;p&gt;Here’s the code snippet to send a test email.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MailTrapEmailAPI {
  public static void sendMail(){
      String body = '{"to": [{"email": "john.doe@example.com", "name": "Mailtrap Inbox"}], "from": {"email": "mailtrap@example.com", "name": "Magic Elves"}, "subject": "You are awesome!", "html": "&amp;lt;!doctype html&amp;gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=UTF-8\\"&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body style=\\"font-family: sans-serif;\\"&amp;gt;&amp;lt;div style=\\"display: block; margin: auto; max-width: 600px;\\" class=\\"main\\"&amp;gt;&amp;lt;h1 style=\\"font-size: 18px; font-weight: bold; margin-top: 20px\\"&amp;gt;Congrats for sending test email with Mailtrap!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;Inspect it using the tabs you see above and learn how this email can be improved.&amp;lt;/p&amp;gt;&amp;lt;img alt=\\"Inspect with Tabs\\" src=\\"https://assets-examples.mailtrap.io/integration-examples/welcome.png\\" style=\\"width: 100%;\\"&amp;gt;&amp;lt;p&amp;gt;Now send your email using our fake SMTP server and integration of your choice!&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Good luck! Hope it works.&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;", "text": "Congrats for sending test email with Mailtrap!\\n\\nInspect it using the tabs above and learn how this email can be improved.\\nNow send your email using our fake SMTP server and integration of your choice!\\n\\nGood luck! Hope it works."}';

      Http http = new Http();
      HttpRequest request = new HttpRequest();
      request.setEndpoint('https://send.api.mailtrap.io/api/send');
      request.setMethod('POST');
      request.setHeader('Api-Token', 'YourMailtrapAPIToken');
      request.setHeader('Content-Type', 'application/json;charset=UTF-8');
      request.setBody(body);
      System.debug('1 ' + request);
      HttpResponse response = http.send(request);
      System.debug('2 ' + response);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here’s the addition to include a string from a List.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; emailAddresses = new List&amp;lt;String&amp;gt;();
// Populate the list with email addresses from your data source
// ...
mail.setToAddresses(emailAddresses);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Mass Send to the Rescue
&lt;/h2&gt;

&lt;p&gt;We’ve covered a lot of ground in this article, diving deep into the process of Salesforce mass email sending. From Apex to testing, and the nuances of Salesforce Classic and Lightning Experience, we’ve seen that Salesforce offers a range of powerful tools for mass emailing.&lt;/p&gt;

&lt;p&gt;As we wrap up our exploration of sending mass emails in Salesforce, keep in mind that each method has its own strengths and considerations. We hope this guide shed some light on these processes and will serve as a stepping stone for your future endeavors in Salesforce. &lt;/p&gt;

&lt;p&gt;Remember, the world of Salesforce is vast and ever-evolving, so keep exploring, keep learning, and most importantly, keep emailing!&lt;/p&gt;

&lt;p&gt;Thank you for choosinf this article! Discover more articles about &lt;a href="https://mailtrap.io/blog/salesforce-mass-email/"&gt;how to send mass email in salesforce&lt;/a&gt; in Mailtrap blog!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Send Emails with Rust – SMTP and API Methods with Examples</title>
      <dc:creator>Veljko Ristic</dc:creator>
      <pubDate>Mon, 11 Dec 2023 10:15:22 +0000</pubDate>
      <link>https://forem.com/veljkoristic/send-emails-with-rust-smtp-and-api-methods-with-examples-np6</link>
      <guid>https://forem.com/veljkoristic/send-emails-with-rust-smtp-and-api-methods-with-examples-np6</guid>
      <description>&lt;p&gt;This article explores the practical steps and considerations for utilizing Rust to manage email sending, from setting up &lt;a href="https://mailtrap.io/smtp-service/"&gt;SMTP&lt;/a&gt; to leveraging APIs for both sending and testing emails.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to send emails using Rust and SMTP
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;lettre&lt;/code&gt; crate is among the most straightforward methods to send emails from Rust via &lt;a href="https://mailtrap.io/smtp-service/"&gt;SMTP&lt;/a&gt;. The following sections cover different scenarios using &lt;code&gt;lettre&lt;/code&gt; crate and they include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending a simple &lt;code&gt;plain.txt&lt;/code&gt; email&lt;/li&gt;
&lt;li&gt;Sending an HTML email&lt;/li&gt;
&lt;li&gt;Sending attachments &lt;/li&gt;
&lt;li&gt;Sending to multiple recipients&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to copy-paste the scripts below minding your credentials as well as recipient and sender addresses, and SMTP endpoints. Also, note that these are designed for &lt;a href="https://mailtrap.io/email-sending/"&gt;Mailtrap Email Sending&lt;/a&gt; SMTP users. &lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vAfUyKpWj_M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Later in the article, we cover the API method. And here, we’d like to offer some pointers for Mailtrap users. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before you start sending your emails, you need to verify your domain with Mailtrap. &lt;/li&gt;
&lt;li&gt;Make sure to use the script with TLS handling, since Mailtrap requires STARTTLS. &lt;/li&gt;
&lt;li&gt;Use only the domain that you set up and verified with Mailtrap. Or, you’ll get the “Unauthorized 401” error. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Send emails using &lt;code&gt;lettre&lt;/code&gt; crate
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add ‘lettre’ to the ‘Cargo.toml’ file:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[dependencies]
lettre = "0.10"
lettre_email = "0.9"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the &lt;code&gt;lettre&lt;/code&gt; and &lt;code&gt;lettre_email&lt;/code&gt;versions might be updated when you’re reading this article. &lt;a href="https://crates.io/"&gt;Click here&lt;/a&gt; for the latest versions. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write the email-sending script:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use lettre::{Message, SmtpTransport, Transport};
use lettre::smtp::authentication::Credentials;

fn main() -&amp;gt; std::result::Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {
    // Define the email
    let email = Message::builder()        .from("Your Name &amp;lt;your.email@example.com&amp;gt;".parse().unwrap())        .reply_to("your.email@example.com".parse().unwrap())        .to("Recipient Name &amp;lt;recipient.email@example.com&amp;gt;".parse().unwrap())        .subject("Rust Email")        .body(String::from("Hello, this is a test email from Rust!"))        .unwrap();
    // Set up the SMTP client    let creds = Credentials::new("Mailtrap_smtp_username".to_string(), "Mailtrap_smtp_password".to_string());
    // Open a remote connection to gmail    let mailer = SmtpTransport::relay("your_mailtrap_Host.io")?        .credentials(creds)        .build();
    // Send the email    match mailer.send(&amp;amp;email) {        Ok(_) =&amp;gt; println!("Email sent successfully!"),        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),    }
    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Replace all the variables with your actual credentials, relay endpoints, and corresponding email addresses.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;*&lt;em&gt;TLS handling *&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you’re a Mailtrap user, TLS handling is required. &lt;code&gt;lettre&lt;/code&gt; supports ‘None’, ‘Starttls’ and ‘Required’ TLS settings. The TLS settings are specified in the &lt;code&gt;SmtpTransport&lt;/code&gt; block, and here’s what the TLS-enabled script might look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use lettre::{Message, SmtpTransport, Transport}; 
use lettre::transport::smtp::{authentication::{Credentials}}; 

fn main() -&amp;gt; std::result::Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {
    // Build an email message using the builder pattern
    let email = Message::builder()
        // Set the sender's name and email address
        .from("Your Name &amp;lt;your address@gmail.com&amp;gt;".parse().unwrap()) 
        // Set the recipient's name and email address
        .to("Recipient Name &amp;lt;receiver address@gmail.com&amp;gt;".parse().unwrap()) 
        // Set the subject of the email
        .subject("Rust Email") 
        // Set the body content of the email
        .body(String::from("Hello World, this is a test email from Rust!")) 
        .unwrap();

    // Create SMTP client credentials using username and password
    let creds = Credentials::new("mailtrap_username".to_string(), "mailtrap_password".to_string()); 

    // Open a secure connection to the SMTP server using STARTTLS
    let mailer = SmtpTransport::starttls_relay("your_mailtrap_host.io")
        .unwrap()  // Unwrap the Result, panics in case of error
        .credentials(creds)  // Provide the credentials to the transport
        .build();  // Construct the transport

    // Attempt to send the email via the SMTP transport
    match mailer.send(&amp;amp;email) { 
        // If email was sent successfully, print confirmation message
        Ok(_) =&amp;gt; println!("Email sent successfully!"), 
        // If there was an error sending the email, print the error
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e), 
    }

    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;your_mailtrap _host&lt;/code&gt; will vary depending on your purpose. For example, if you’re using Mailtrap Email Testing, then the Host is &lt;code&gt;sandbox.smtp.mailbox.io&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run your application&lt;/strong&gt;
Use the &lt;code&gt;cargo run&lt;/code&gt; command to run your application. Assuming the setup is correct, rust will send the email to specified recipients. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to send HTML email with Rust?
&lt;/h3&gt;

&lt;p&gt;To send an HTML email, we’ll reuse and modify the &lt;code&gt;lettre&lt;/code&gt; script with STARTTLS.&lt;/p&gt;

&lt;p&gt;Simply, you need to set the content type of the email body to &lt;code&gt;text/html&lt;/code&gt;. This can be done by using the &lt;code&gt;message::SinglePart&lt;/code&gt; and &lt;code&gt;message::MultiPart&lt;/code&gt; modules to construct the email body properly.&lt;/p&gt;

&lt;p&gt;Here’s the modified code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
use lettre::message::{Mailbox, MultiPart, SinglePart};

fn main() -&amp;gt;  std::result::Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {

    // Define the HTML content
    let html_content = r#"
        &amp;lt;html&amp;gt;
            &amp;lt;body&amp;gt;
                &amp;lt;h1&amp;gt;Hello!&amp;lt;/h1&amp;gt;
                &amp;lt;p&amp;gt;This is a &amp;lt;strong&amp;gt;test email&amp;lt;/strong&amp;gt; from Rust!&amp;lt;/p&amp;gt;
            &amp;lt;/body&amp;gt;
        &amp;lt;/html&amp;gt;
    "#;

    let from_email = "Your Name &amp;lt;sender@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();
    let to_email = "Recipient Name &amp;lt;recipient@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();

    // Define the email with HTML part
    let email = Message::builder()
        .from(from_email)
        .to(to_email)
        .subject("Rust Email")
        .multipart(
            MultiPart::alternative().singlepart(SinglePart::html(html_content.to_string())),
        )
        .unwrap();

    // Set up the SMTP client credentials
    let creds = Credentials::new("username".to_string(), "password".to_string());

    // Open a remote connection to the SMTP server with STARTTLS
    let mailer = SmtpTransport::starttls_relay("your_mailtrap_host.io")
        .unwrap()
        .credentials(creds)
        .build();

    // Send the email
    match mailer.send(&amp;amp;email) {
        Ok(_) =&amp;gt; println!("Email sent successfully!"),
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),
    }

    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Notes on code modifications:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;html_content&lt;/code&gt; variable holds the HTML content of the email.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Message::builder()&lt;/code&gt; is used to set up the headers of the email.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;multipart()&lt;/code&gt; method is used to create a MultiPart email, which can contain both text and HTML parts. In this case, we’re only adding an HTML part using &lt;code&gt;SinglePart::html(html_content.to_string())&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to send an email with attachments in Rust?
&lt;/h3&gt;

&lt;p&gt;Again, we’ll reuse and modify the script above to include attachments.&lt;/p&gt;

&lt;p&gt;This code demonstrates how to send an email with attachments using the &lt;code&gt;lettre&lt;/code&gt; crate in Rust and the Mailtrap SMTP server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use lettre::transport::smtp::authentication::Credentials;
use lettre::{Message, SmtpTransport, Transport};
use lettre::message::{Mailbox, MultiPart, SinglePart, Attachment, Body};
use std::fs;

fn main() -&amp;gt; std::result::Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {


    let image = fs::read("picture.png")?;
    let image_body = Body::new(image);

    let from_email = "Your Name &amp;lt;sender@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();
    let to_email = "Recipient Name &amp;lt;recipient-email@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();

    let email = Message::builder()
                    .from(from_email)
                    .to(to_email)
                    .subject("Hello")
                    .multipart(
                        MultiPart::mixed()
                            .multipart(
                                MultiPart::alternative()
                                    .singlepart(SinglePart::plain(String::from("Hello, world! :)")))
                                    .multipart(
                                        MultiPart::related()
                                            .singlepart(SinglePart::html(String::from(
                                                "&amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Hello&amp;lt;/b&amp;gt;, &amp;lt;i&amp;gt;world&amp;lt;/i&amp;gt;! &amp;lt;img src=cid:123&amp;gt;&amp;lt;/p&amp;gt;",
                                            )))
                                            .singlepart(
                                                Attachment::new_inline(String::from("123"))
                                                    .body(image_body, "image/png".parse().unwrap()),
                                            ),
                                    ),
                            )
                            .singlepart(Attachment::new(String::from("example.com")).body(
                                String::from("fn main() { println!(\"Hello, World!\") }"),
                                "text/plain".parse().unwrap(),
                            )),
                    )?;

    let creds = Credentials::new("username".to_string(), "password".to_string());

    // Open a remote connection to the SMTP server with STARTTLS
    let mailer = SmtpTransport::starttls_relay("your_mailtrap_hosting.io").unwrap()
        .credentials(creds)
        .build();

    // Send the email
    match mailer.send(&amp;amp;email) {
        Ok(_) =&amp;gt; println!("Email sent successfully!"),
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),
    }

    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notes on code modifications:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code uses the &lt;code&gt;fs::read&lt;/code&gt; function from the &lt;code&gt;std&lt;/code&gt; library to read the contents of the &lt;code&gt;"picture.png"&lt;/code&gt; file into a byte vector. This byte vector is then wrapped in a &lt;code&gt;Body&lt;/code&gt; object, which represents the body of the image attachment.&lt;/li&gt;
&lt;li&gt;In this example, a multipart email is created using &lt;code&gt;MultiPart::mixed()&lt;/code&gt;. This multipart email consists of two parts: an alternative multipart (containing a plain text part and a related multipart) and a single-part attachment.&lt;/li&gt;
&lt;li&gt;The alternative multipart holds both a plain text part (&lt;code&gt;SinglePart::plain&lt;/code&gt;) and a related multipart. The related multipart contains an HTML part (&lt;code&gt;SinglePart::html&lt;/code&gt;) with an embedded image attachment (&lt;code&gt;Attachment::new_inline&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The single-part attachment contains a source code file called &lt;code&gt;"example.com"&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When using the script, you need to replace the &lt;code&gt;"picture.png"&lt;/code&gt;, with the file path you’re using.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending email to multiple recipients using Rust
&lt;/h3&gt;

&lt;p&gt;You can send to multiple recipients by chaining  &lt;code&gt;.to()&lt;/code&gt;,&lt;code&gt;.cc()&lt;/code&gt;, and&lt;code&gt;.bcc()&lt;/code&gt;methods. Each recipient is added by parsing a string that contains the email address and optionally the name of the recipient. &lt;/p&gt;

&lt;p&gt;Check the updated sending script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// [dependencies]
// lettre="0.10"

use lettre::{transport::smtp::authentication::Credentials, Message, SmtpTransport, Transport};
use lettre::message::{Mailbox, MultiPart, SinglePart};

fn main() -&amp;gt;  std::result::Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {

    // Define the HTML content
    let html_content = r#"
        &amp;lt;html&amp;gt;
            &amp;lt;body&amp;gt;
                &amp;lt;h1&amp;gt;Hello!&amp;lt;/h1&amp;gt;
                &amp;lt;p&amp;gt;This is a &amp;lt;strong&amp;gt;test email&amp;lt;/strong&amp;gt; from Rust!&amp;lt;/p&amp;gt;
            &amp;lt;/body&amp;gt;
        &amp;lt;/html&amp;gt;
    "#;

    let from_email = "Your Name &amp;lt;sender@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();
    let to_email = "Recipient Name &amp;lt;receiver@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap();

    // Define the email with HTML part
    let email = Message::builder()
        .from(from_email)
        .to(to_email) 
        // You can also add CC and BCC recipients
        .cc("Recipient CC &amp;lt;recipient.cc@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap())
        .bcc("Recipient BCC &amp;lt;recipient.bcc@example.com&amp;gt;".parse::&amp;lt;Mailbox&amp;gt;().unwrap())
        .subject("Rust Email")
        .multipart(
            MultiPart::alternative().singlepart(SinglePart::html(html_content.to_string())),
        )
        .unwrap();

    // Set up the SMTP client credentials
    let creds = Credentials::new("username".to_string(), "password".to_string());

    // Open a remote connection to the SMTP server with STARTTLS
    let mailer = SmtpTransport::starttls_relay("your_mailtrap_hosting.io")
        .unwrap()
        .credentials(creds)
        .build();

    // Send the email
    match mailer.send(&amp;amp;email) {
        Ok(_) =&amp;gt; println!("Email sent successfully!"),
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),
    }

    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to send emails using Rust and Mailtrap API?
&lt;/h2&gt;

&lt;p&gt;To send emails using the &lt;a href="https://api-docs.mailtrap.io/docs/mailtrap-api-docs/5tjdeg9545058-mailtrap-api?_ga=2.162577724.1635651381.1700475414-1401282675.1644409633"&gt;Mailtrap Email Sending API&lt;/a&gt; in Rust, use an HTTP client library to make a POST request to the API endpoint. &lt;/p&gt;

&lt;p&gt;The commonly used HTTP client library in Rust is &lt;code&gt;reqwest&lt;/code&gt;, and I chose it because it’s among the easiest to implement.&lt;/p&gt;

&lt;p&gt;Now, start by adding the necessary dependencies. Add &lt;code&gt;reqwest&lt;/code&gt; and tokio to your &lt;code&gt;Cargo.toml&lt;/code&gt; because &lt;code&gt;reqwest&lt;/code&gt; is an async library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1.0"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s an exemplary script to send emails with Rust and Mailtrap API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use reqwest;
use serde_json::json;

#[tokio::main]
async fn main() -&amp;gt; Result&amp;lt;(), reqwest::Error&amp;gt; {
    let api_url = "https://send.api.mailtrap.io/api/send";
    let api_key = "your_api_key";
    let email_payload = json!({
        "from": {"email" : "your_verified_domain"},
        "to": [{"email": "receiver@example.com"}],
        "subject": "Test Email",
        "text": "This is a test email using Rust and Mailtrap API!",
    });

    let client = reqwest::Client::new();
    let response = client
        .post(api_url)
        .header("Content-Type", "application/json")
        .header("Api-Token", api_key)
        .body(email_payload.to_string()) // Serialize the JSON payload to a string
        .send()
        .await?;

    if response.status().is_success() {
        println!("Email sent successfully!");
    } else {
        println!("Failed to send email. Status: {:?}", response.status());

        // Print the response body for additional information
        let body = response.text().await?;
        println!("Response body: {}", body);
    }

    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notes on the Mailtrap API method:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;email_payload&lt;/code&gt; variable contains a JSON object that represents the email data. &lt;/li&gt;
&lt;li&gt;A client instance is created using &lt;code&gt;reqwest::Client::new()&lt;/code&gt;. This client will be used to make the POST request to the Mailtrap API.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;client.post(api_url)&lt;/code&gt; method creates a POST request to the specified endpoint URL. The headers are set using the &lt;code&gt;.header()&lt;/code&gt; method, including the Content-Type header as &lt;code&gt;"application/json"&lt;/code&gt; and the API-Token header as the Mailtrap API key. &lt;/li&gt;
&lt;li&gt;The email payload is serialized to a string using &lt;code&gt;email_payload.to_string()&lt;/code&gt; and set as the request body using the &lt;code&gt;.body()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;send()&lt;/code&gt;method sends the request and returns a future that resolves to a &lt;code&gt;Result&amp;lt;Response, reqwest::Error&amp;gt;&lt;/code&gt; The &lt;code&gt;await&lt;/code&gt; keyword is used to await the completion of the request and get the response.&lt;/li&gt;
&lt;li&gt;The response status is checked using the &lt;code&gt;.status()&lt;/code&gt; method. If the status indicates &lt;code&gt;success (2xx)&lt;/code&gt; a success message is printed. Otherwise, an error message is printed along with the response status. &lt;/li&gt;
&lt;li&gt;Any errors that occur during the request or response handling are propagated by returning a &lt;code&gt;Result&amp;lt;(), reqwest::Error&amp;gt; from the main()&lt;/code&gt; function. Error handling in Rust typically involves propagating the error upwards in the call stack by returning it from the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before running this code, ensure that you have the reqwest and tokio crates added to your Cargo.toml file with the appropriate versions and features enabled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Send emails using &lt;code&gt;sendmail&lt;/code&gt; crate
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;sendmail&lt;/code&gt; crate sends emails by interfacing with the &lt;code&gt;sendmail&lt;/code&gt; command available on many Unix-like systems. This means that the system where your Rust application is running must have a sendmail-compatible program installed and properly configured.&lt;/p&gt;

&lt;p&gt;The quick tutorial below assumes you have a proper sendmail-compatible program installed and configured. Otherwise, the method won’t work. &lt;/p&gt;

&lt;p&gt;If you need a tutorial on &lt;a href="https://tecadmin.net/install-sendmail-on-ubuntu/"&gt;setting up sendmail on Ubuntu&lt;/a&gt;, check the one in the link. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add &lt;code&gt;sendmail&lt;/code&gt; command to the &lt;code&gt;Cargo.toml&lt;/code&gt;:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[dependencies]
sendmail = "2.0"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use the script below to send your email:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extern crate sendmail;
use sendmail::email;

fn main() {

    // Configure email body and header
    // Send the email
    match email::send(
        // From Address
        "sender@example.com",
        // To Address
        &amp;amp;["receiver@example.com"],
        // Subject
        "Subject - Hello World!",
        // Body
        "&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;I am the body. Hello Wolrd!&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;And I accept html.&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"
    ) {
        Ok(_) =&amp;gt; println!("Email sent successfully!"),
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Keynotes on using the &lt;code&gt;sendmail&lt;/code&gt; crate:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sendmail(&amp;amp;email)&lt;/code&gt; is used to send the email. This function takes the email object and sends it using the system’s sendmail command.&lt;/li&gt;
&lt;li&gt;As the method relies on the system-level &lt;code&gt;sendmail&lt;/code&gt; command, it’s less “portable” than the &lt;code&gt;lettre&lt;/code&gt; which can work across different platforms without system-specific tools. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rust email testing: reasons and how-tos
&lt;/h2&gt;

&lt;p&gt;There are five reasons to consider email testing with Rust:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verification of Logic:&lt;/strong&gt; Ensure that your email-sending logic works as expected under various conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Accuracy:&lt;/strong&gt; Make sure that the content of the emails, including subject, body (both text and HTML), and attachments, is correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling:&lt;/strong&gt; Test how your application handles failures, such as network issues or incorrect credentials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; Understand how your email sending performs under load. This is especially important if you’re sending large volumes of email.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Ensure that your email-sending process is secure and that sensitive information is handled correctly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Also, there are three types of tests you can run: integration, unit, and end-to-end testing. Check the details below. &lt;/p&gt;

&lt;h3&gt;
  
  
  Integration testing with Mailtrap Testing SMTP
&lt;/h3&gt;

&lt;p&gt;Use &lt;a href="https://mailtrap.io/email-sandbox/"&gt;Mailtrap Email Testing&lt;/a&gt; for integration tests. It gives you a safe environment to inspect and debug your emails without the risk of spamming your recipients. &lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AveaJc6c3fI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here’s an exemplary code for Mailtrap users. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Run this application with ‘cargo test’ command to see the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example of integration test with a fake SMTP server
fn send_test_email() -&amp;gt; Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {
        // Build the email
    let email = EmailBuilder::new()
        // Addresses can be specified by the tuple (email, alias)
        .to(("recipient.email@example.com", "Recipient Name"))
        .from(("your.email@example.com", "Your Name"))
        .subject("Rust Email")
        .body("Hello, this is a test email from Rust!")
        .build()?;

    // Send the email
    match sendmail(&amp;amp;email) {
        Ok(_) =&amp;gt; println!("Email sent successfully!"),
        Err(e) =&amp;gt; eprintln!("Could not send email: {:?}", e),
    }

    Ok(())

}

#[test]
fn test_email_integration() {
    // Start a fake SMTP server before running the test
    // ...

    let result = send_test_email();
    assert!(result.is_ok());

    // Check the fake SMTP server for the sent email
    // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; The code above doesn’t contain an exemplary email template. &lt;/p&gt;

&lt;p&gt;As mentioned this integration test is for Mailtrap users, if you’re not a user, you can &lt;a href="https://mailtrap.io/register/signup?ref=header"&gt;sign up here&lt;/a&gt;. We offer a free plan where you can check things out at a rate of 100 emails a month with a throughput of 5 emails per 10 seconds. &lt;/p&gt;

&lt;p&gt;Here’s a quick overview of what you get with Mailtrap Email Testing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mailtrap.io/fake-smtp-server/"&gt;Fake SMTP Server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mailtrap.io/html-email-checker/"&gt;HTML/CSS check &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mailtrap.io/email-spam-checker/"&gt;Spam score check &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mailtrap.io/qa-automation/"&gt;API for QA automation&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Integrations in 20+ languages (Ruby, Python, PHP, Node.js, .Net, etc.) &lt;/li&gt;
&lt;li&gt;Emails preview &lt;/li&gt;
&lt;li&gt;Multiple inboxes for different projects and stages&lt;/li&gt;
&lt;li&gt;User management&lt;/li&gt;
&lt;li&gt;SSO &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Integration testing with Mailtrap Testing API
&lt;/h3&gt;

&lt;p&gt;We’ll follow a similar approach used for Mailtrap Email Sending API. Only, this time the endpoints and details are specific to the testing API. &lt;/p&gt;

&lt;p&gt;Again, you need the &lt;code&gt;reqwest&lt;/code&gt; and &lt;code&gt;tokio&lt;/code&gt; crates in the &lt;code&gt;Cargo.toml&lt;/code&gt; file to may asynchronous HTTP requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[dependencies]
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1.0"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here’s a exemplary API testing script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use reqwest;
use serde_json::json;
use tokio;

#[tokio::main]
async fn main() -&amp;gt; Result&amp;lt;(), Box&amp;lt;dyn std::error::Error&amp;gt;&amp;gt; {
    let api_url = "https://sandbox.api.mailtrap.io/api/send/inbox_id"; // Replace 'inbox_id' with your actual Mailtrap inbox ID
    let api_token = "api_token"; // Replace with your actual Mailtrap API token

    let client = reqwest::Client::new();

    let payload = json!({
        "to": [
            {
                "email": "receiver@gmail.com",
                "name": "receiver name"
            }
        ],
        "from": {
            "email": "your.domain.link",
            "name": "Example Sales Team"
        },
        "subject": "Your Example Order Confirmation",
        "text": "Congratulations on your order no. 1234",
        "category": "API Test"
    });

    let response = client.post(api_url)
        .header("Content-Type", "application/json")
        .header("Accept", "application/json")
        .header("Api-Token", api_token)
        .json(&amp;amp;payload)
        .send()
        .await?;

    if response.status().is_success() {
        println!("Email sent successfully!");
    } else {
        println!("Failed to send email. Status: {:?}", response.status());

        // Print the response body for additional information
        let body = response.text().await?;
        println!("Response body: {}", body);
    }


    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Keynotes about the API testing script:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;"inbox_id"&lt;/code&gt; with your actual Mailtrap inbox ID (integer).&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;"your_api_token"&lt;/code&gt; with your actual Mailtrap API token.&lt;/li&gt;
&lt;li&gt;The payload is constructed using &lt;code&gt;serde_json::json!&lt;/code&gt; macro to create a JSON object.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;reqwest::Client&lt;/code&gt; is used to make a POST request to the Mailtrap Testing API endpoint.
The response is checked for success, and the response body is printed out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lastly, you should run the code within an async environment since &lt;code&gt;reqwest&lt;/code&gt; is an asynchronous library. The &lt;code&gt;#[tokio::main]&lt;/code&gt; attribute macro is used to set up an asynchronous runtime for the main function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unit testing
&lt;/h3&gt;

&lt;p&gt;Unit testing allows you to mock the components that send emails. Rust libraries designed for that are &lt;code&gt;mockall&lt;/code&gt; or &lt;code&gt;mockito&lt;/code&gt;, and they create mock objects in the tests. &lt;/p&gt;

&lt;p&gt;The below is a simplified version of how you might mock an email sender.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use mockall::predicate::*;
use mockall::Sequence;
use mockall::automock;

#[automock]
trait EmailSender {
    fn send_email(&amp;amp;self, recipient: &amp;amp;str, subject: &amp;amp;str, body: &amp;amp;str) -&amp;gt; Result&amp;lt;(), String&amp;gt;;
}

struct MyComponent&amp;lt;T: EmailSender&amp;gt; {
    email_sender: T,
}

impl&amp;lt;T: EmailSender&amp;gt; MyComponent&amp;lt;T&amp;gt; {
    pub fn new(email_sender: T) -&amp;gt; Self {
        MyComponent { email_sender }
    }

    pub fn do_something(&amp;amp;self) -&amp;gt; Result&amp;lt;(), String&amp;gt; {
        // Code that uses the email sender component
        let recipient = "recipeint@example.com";
        let subject = "Test Subject";
        let body = "Test Body";

        self.email_sender.send_email(recipient, subject, body)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_do_something() {
        let mut email_sender = MockEmailSender::new();

        let recipient = "recipient@example.com";
        let subject = "Test Subject";
        let body = "Test Body";

        // Set up expectations for the mock object
        email_sender.expect_send_email()
            .once()
            .withf(move |r, s, b| r == recipient &amp;amp;&amp;amp; s == subject &amp;amp;&amp;amp; b == body)
            .returning(|_, _, _| Ok(()));

        let my_component = MyComponent::new(email_sender);
        let result = my_component.do_something();

        assert!(result.is_ok());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key notes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;#[automock]&lt;/code&gt; attribute is used before the &lt;code&gt;EmailSender&lt;/code&gt; trait definition. This attribute generates an implementation of the trait with all its methods implemented as mock methods. It allows you to set expectations on the behavior of the mock object during testing.&lt;/li&gt;
&lt;li&gt;Using the &lt;code&gt;expect_send_email&lt;/code&gt; method on the &lt;code&gt;email_sender&lt;/code&gt; mock object, you set expectations for the &lt;code&gt;send_email&lt;/code&gt; method of the mock object. &lt;/li&gt;
&lt;li&gt;In the exemplary script, the method should be called once (&lt;code&gt;once()&lt;/code&gt;) and with the expected recipient, subject, and body values. We use the &lt;code&gt;withf&lt;/code&gt; method to define a closure that checks if the passed arguments match the expected ones.&lt;/li&gt;
&lt;li&gt;The returning method is used to define the return value of the &lt;code&gt;send_email&lt;/code&gt; method, which in this case is &lt;code&gt;Ok(())&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;I created an instance of &lt;code&gt;MyComponent&lt;/code&gt; by passing the mocked &lt;code&gt;email_sender&lt;/code&gt; object. Then, we call the &lt;code&gt;do_something&lt;/code&gt; method on the instance and store the result in the result variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  End-to-end testing
&lt;/h3&gt;

&lt;p&gt;To run end-to-end tests, you might actually send production (not sandbox) emails to a controlled set of email addresses. Then, you could use a specific API or service to confirm that the emails were received and contain the right content. &lt;/p&gt;

&lt;p&gt;There’s no exemplary code here as it depends on the type of emails you want to test, what services you’re using, and your overall approach. So, it’s a topic on its own and won’t be covered in detail here. &lt;/p&gt;

&lt;p&gt;However, if you run integration testing, end-to-end might not be necessary. &lt;/p&gt;

&lt;h2&gt;
  
  
  Trust Rust
&lt;/h2&gt;

&lt;p&gt;Rust’s versatility extends to email communication, providing developers with powerful tools to send and test emails effectively. Whether through SMTP or API integration, the language’s safety features and performance make it an excellent choice for managing email-related tasks in modern applications.&lt;/p&gt;

&lt;p&gt;Thank you for reading this article! Follow Mailtrap blog and discover more about &lt;a href="https://mailtrap.io/blog/rust-send-email/"&gt;sending emails using Rust and SMTP&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rust</category>
    </item>
  </channel>
</rss>
