Features > Email
✉️ Mailgun
While Mailgun is a viable option, any email tool will work for setting up features like magic login links, abandoned cart emails, etc.Setup
Tips
Mailgun quietly removed the "pay-as-you-go" flex tier from their pricing page, but it's still accessible. Start a free trial for the $35 tier, then cancel it. You'll revert to the "pay-as-you-go" free tier. If you send fewer than 1000 emails per month, the cost will be $1 per month.Opting for Resend? Check out an outstanding tutorial created by another indie hacker like yourselves.
1. Sign up for a new account on Mailgun
2. In the [Sending] section, click [Domains], and then select [Add New Domain]. It's suggested to add a subdomain, such as mail.yourexampledomain.com.
Tips
url: "https://api.eu.mailgun.net/"
3. Finish all the DNS verification procedures. If you're using a subdomain, make sure it's correctly configured in your DNS records.
4. Add extra DMARC for better deliverability: TXT | _dmarc.mail.yourdomain.com | v=DMARC1; p=none
5. Go to [Domain Settings], followed by [SMTP Credentials], then opt for [Reset Password]. Select [Automatic] and go to [Create Password].
6. Click on [Copy] placed at the lower-right corner of the modal. In .env.local, configure EMAIL_SERVER to: smtp://postmaster@[mail.yourdomain.com]:[copied_password]@smtp.mailgun.org:587 (don't include the the brackets).
7. On the [Sending API Keys] section, hit [Create sending key], and then place it into .env.local as MAILGUN_API_KEY.
(If you don't need to receive emails, you can skip this step.) Within [Receiving], choose [Create Route]. Pick [Match Recipient] and Enter the email address you plan to send from (e.g., name@mail.yourdomain.com). Make sure it matches the email configured at mailgun.supportEmail in the config.ts file.
Forward it to https://[your-domain].com/api/webhook/mailgun. Click [Create Route]. Then, add your receiving email address (e.g., using my Gmail) to mailgun.forwardRepliesTo in the config.ts.
Tips
Verify that your records are valid on MxToolbox (If you used a subdomain, please enter it here.)Sending Emails
There are two ways of sending emails:
1. SMTP: Emails, such as magic login links, will be sent via SMTP.
2. Mailgun API: For sending different kinds of emails, use the sendEmail() function located at libs/mailgun.js.
Receiving emails
Mailgun doesn't automatically forward emails to other places or save them.
That's why we made a system for emails sent to our support email (mentioned in config.ts) to be sent to our API (your-domain.com/api/webhook/mailgun). After that, they're sent to the email address we specified in the "forwardRepliesTo" setting. config.ts.
It automatically adds the sender to the reply-to field, so you can reply directly from your inbox.
Checklist for avoiding spam
✅ Use subdomain to send emails (i.e. mail.yourdomain.com)
✅ Add an SPF record (in subdomain)
✅ Add an DKIM record (in subdomain)
✅ Add an DMARC record (in subdomain)
✅ Add an ubsubscribe link at the bottom
✅ Customize the email by including the recipient's name.
❗ Use words that are less likely to trigger spam filters, like free or earn money
❗ Stay away from unusual fonts, odd layouts, or excessive punctuation.
❗ Stay away from the links to non-reputable websites