Sending Emails
We are using Resend for sending emails follow the guides below to
set it up or replace it.
Setup Resend
- Start by creating an account on
Resendhere. - Navigate to
Domainsthen click on+ Add Domain- It is better to use a subdomain read why here
- Follow the DNS verification steps then click on
Verify DNS Records - Navigate to
API Keysthen click+ Create API Key - Copy the API key then add it to
.env.locallike so
.env.local
RESEND_KEY= # your Resend api key here
Sending your first email
- Add your from email to
config.ts
/src/utils/config.ts
const config = {
//...
email: {
from: "no-reply@example_domain.com",
//...
},
//...
};
- 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
- Replace
RESEND_KEYfrom.env.localto reflect the tool you are using - Update
/src/lib/emailapi 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.