Emails

Email Setup Documentation

Previously, we used the Resend service to handle emails. However, we moved away from it due to several issues:

  • Emails often failed to reach the inbox folder due to problems with their SMTP servers.

  • The free plan had significant limitations, such as allowing only one audience and restricting the number of contacts or emails.

To address these issues, we are pleased to introduce a new custom email marketing system integrated into our SaasCore boilerplate.

Benefits of the New System

  • Unlimited Emails: Send as many emails as you want.

  • Unlimited Audiences: Create unlimited audience groups.

  • Automation: Send automated emails effortlessly.

  • Flexible SMTP Options: Use any SMTP server you prefer, such as Zoho Mail, SendGrid, or even Resend (if desired).


Setup Instructions

Using Zoho Mail for SMTP

Personally, I use the free professional Zoho Mail plan to quickly create new emails for every SaaS project I launch.

Configuration for Zoho Mail:

envCopy codeSMTP_HOST=smtp.zoho.com  
SMTP_PORT=465  
SMTP_SECURE=true  
SMTP_USER=  
SMTP_PASSWORD=  

To configure:

  1. Enter your Zoho email and password into the SMTP_USER and SMTP_PASSWORD fields.

  2. That's it! Your email setup is ready to go.


Adding Audiences and Managing Emails

In the configuration file, there's a customAudiences property that allows you to manage audiences.

Steps to Add a New Audience:

  1. During setup, create a new audience in the Audiences section of the admin panel.

  2. Each audience created will have a unique ID. This ID is required to programmatically add emails to the specific audience.

Example configuration in the code:

customAudiences: {
    newsletterAudienceId: "...", // ID for newsletter subscribers 
}

Example: Adding Emails to "Blog newsletter" Audience

  1. Create a new audience named "Blog Newsletter" in the admin panel.

  2. Copy the unique audience ID and paste it into the configuration file under newsletterAudienceId.

  3. When prospects submit their emails through the newsletter subscriptioncomponent, they will automatically be added to this audience using the addToCustomAudience utility function.

Utility function implementation we use:

export async function addToCustomAudience({
    email,
    customAudienceId,
}: {
    email: string;
    customAudienceId: string;
}) {
    try {
        // Check if the email already exists
        const existingContact = await prisma.customAudienceEmail.findUnique({
            where: {
                email_customAudienceId: {
                    email: email,
                    customAudienceId: customAudienceId,
                },
            },
        });

        if (existingContact) {
            return { error: "Email already exists" };
        }

        // Add the email to the audience
        await prisma.customAudienceEmail.create({
            data: {
                email,
                customAudienceId: customAudienceId,
            },
        });
        return { success: "Email added successfully" };
    } catch (error) {
        return { error: "Error adding email" };
    }
}

Usage Example:

We call the addToCustomAudience function as follows: (In the case of potential clients, this function is triggered whenever a client enters their email into the emails collector component.)

 await addToCustomAudience({
    email: values.email,
    customAudienceId:
        config.marketing.customAudiences.newsletterAudienceId
```,
});

Unlimited Audiences and Flexibility

You can repeat this process to create and manage unlimited audiences. Simply add the audience ID to the configuration and use the same flow to manage emails efficiently.

If you have any questions about this setup, feel free to reach out via Discord or email.

Last updated