Sending Emails

    We are using Resend for sending emails follow the guides below to set it up or replace it.

    Setup Resend

    1. Start by creating an account on Resend here.
    2. Navigate to Domains then click on + Add Domain
      • It is better to use a subdomain read why here
    3. Follow the DNS verification steps then click on Verify DNS Records
    4. Navigate to API Keys then click + Create API Key
    5. Copy the API key then add it to .env.local like so

    .env.local

    RESEND_KEY= # your Resend api key here
    

    Sending your first email

    1. Add your from email to config.ts

    /src/utils/config.ts

    const config = {
      //...
      email: {
        from: "no-reply@example_domain.com",
        //...
      },
      //...
    };
    
    1. Remember this can only be used on the server.

    TypeScript

    import { sendEmail } from "lib/email";
    
    await sendEmail({
      to: "example@email.com",
      subject: "My first email",
      html: "<p>hello world!</p>",
      text: "hello world",
    });
    

    Receiving emails

    Because resend does not support replying to emails add your replyTo email to config.ts like so

    /src/utils/config.ts

    const config = {
      //...
      email: {
        //...
        replyTo: "support@example_domain.com",
        //...
      },
      //...
    };
    

    Then where you want to allow reply pass true as second param to sendEmail

    TypeScript

    import { sendEmail } from "lib/email";
    
    await sendEmail(
      {
        to: "example@email.com",
        subject: "My first email",
        html: "<p>hello world!</p>",
        text: "hello world",
      },
      true,
    );
    

    Replace Resend

    1. Replace RESEND_KEY from .env.local to reflect the tool you are using
    2. Update /src/lib/email api call accordingly

    Avoid spam folder

    • Make sure to provide a clear option for recipients to opt out at the bottom.
    • Use simple, professional designs with standard fonts and avoid excessive symbols.
    • Ensure all links in your email direct to credible and trustworthy sites.
    • Stay away from words that often trigger spam filters, such as "exclusive offer" or "get rich."
    • Add SPF record to verify email delivery from your subdomain.
    • Add DKIM record for enhanced email security.
    • Add DMARC record to protect your subdomain from spoofing.
    • Send emails through a specific subdomain, like subdomain.domain.com.
    • Address recipients by their name to make the email feel personal.