Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sanukdev's avatar

Transactional Emails for SAAS

Help me understand the transactional email process for my app. Newbie in the world of developing.

  • Problem One: I have my customers that will need standard transactional emails sent BUT My customer needs to be able to send emails to their customer. Does that all fit under one account (my account) with someone like SendGrid or Mailtrap?

  • Problem Two: My customer needs to have the option to have the "send from" email be their own, not mine.

  • Problem Three: It obviously needs to have a high deliverability, non-spammy success.

0 likes
3 replies
LaryAI's avatar
Level 58

To address your questions about implementing transactional emails for your SAAS application, let's break down each problem and provide a solution.

Problem One: Single Account for Sending Emails

You can use a single account with an email service provider like SendGrid or Mailtrap to send emails on behalf of your customers. However, you need to ensure that you manage the email sending process correctly to avoid any deliverability issues.

Solution:

  • SendGrid: You can use SendGrid's API to send emails on behalf of your customers. You can manage different sender identities and use dynamic templates to customize the emails for each customer.
  • Mailtrap: Mailtrap is generally used for testing emails in a development environment. For production, SendGrid or another transactional email service is recommended.

Problem Two: Custom "Send From" Email

To allow your customers to send emails from their own email addresses, you need to set up domain authentication and use the appropriate headers to specify the "From" address.

Solution:

  1. Domain Authentication: Ensure that your customers' domains are authenticated with your email service provider. This typically involves setting up SPF, DKIM, and DMARC records.
  2. Dynamic "From" Address: Use the email service provider's API to set the "From" address dynamically based on your customer's input.

Here is an example using SendGrid's API in a Node.js application:

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

const sendEmail = async (to, from, subject, text) => {
  const msg = {
    to: to,
    from: from, // This should be the customer's email address
    subject: subject,
    text: text,
  };

  try {
    await sgMail.send(msg);
    console.log('Email sent successfully');
  } catch (error) {
    console.error('Error sending email:', error);
  }
};

// Example usage
sendEmail('[email protected]', '[email protected]', 'Welcome!', 'Hello, welcome to our service!');

Problem Three: High Deliverability

To ensure high deliverability and avoid emails being marked as spam, follow these best practices:

Solution:

  1. Authenticate Your Domain: As mentioned earlier, set up SPF, DKIM, and DMARC records for your domain.
  2. Monitor Your Sending Reputation: Use tools provided by your email service provider to monitor your sending reputation and take action if it starts to decline.
  3. Avoid Spam Triggers: Ensure your email content is clean and free from common spam triggers. Avoid excessive use of promotional language and ensure your emails are relevant to the recipients.
  4. Use Double Opt-In: Ensure that your customers' customers have explicitly opted in to receive emails. This reduces the likelihood of your emails being marked as spam.

By following these steps, you can set up a robust transactional email system for your SAAS application that meets your customers' needs and ensures high deliverability.

If you have any further questions or need more detailed code examples, feel free to ask!

MohamedTammam's avatar

You can have different send from emails with using something like SendGrid. Just add from value when send the mail and it needs to be verified on the mail service.

And you can have different email services (you and customer) for different purpose from the config.

martinbean's avatar

@sanukdev In that’s the case, then I’d be making each customer create their own account, and then providing them a screen to enter their own API keys for SendGrid, Mailtrip, etc.

The reason being, you don’t want to mix clients in your own email service, as if one client does send spammy or otherwise nefarious emails, then that will impact everyone else, including you. So try and isolate clients. If one does act badly, it will only be their own account’s IP address that they’ll be impacting, and you and your other clients will be insulated from that bad activity.

Please or to participate in this conversation.