Saturday, May 17, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Sending Transactional Emails with Remix and Amazon AWS SES

December 5, 2023
in Front-Tech
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter



Almost any web app with authenticated users will need to send some emails. You could work around it by using an authenticated service like Auth0 or AWS Incognito, but let’s assume you’ve set up Remix with a stack that ships with built-in authentication. Kent C. Dodds’ Epic Stack comes pre-wired to use Resend, and that’s a great option; however, my current client already has a large AWS infrastructure setup, so it makes sense to use Amazon’s Simple Email Service (SES).

The Plan
AWS publishes an SES package on NPM that I could use directly, but I’m not going to do that for two reasons:
1. Switching email services later will involve a major re-write
2. It’s hard to use

Nodemailer is the de-facto standard for sending emails from Node, and since Remix is basically React Router Node Edition™️, it will work with Remix. Nodemailer is going to handle all the tricky bits of proper email formatting. Combining Nodemailer with the SES adapter will be easier than making SES work on its own, and if we choose to switch from SES in the future, it will be quick to change.

AWS Credentials
You’ll need to add SESFullAccess permissions to your server’s IAM (Identity and Access Management, how AWS manages permissions). Setting up AWS is outside the scope of this guide. You are here because you have to use AWS, so ask the person who manages AWS for your organization. If you want the less complex mail-sending route, use Resend.

Packages to Install
Nodemailer: nodemailer
With millions of weekly downloads, this is a trusted email service for Node. It will do the heavy lifting of making sure our emails are correctly formatted for SES.

Nodemailer Types: @types/nodemailer
Assuming you are using Typescript. Leave this out if you are using JavaScript.

Client SES: @aws-sdk/client-ses
This package from the AWS SDK will help us tie into SES with minimal headache.

Credential Provider Node: @aws-sdk/credential-provider-node
Amazon has several ways of securely handling credentials, and this package handles all of them. It will look in your Node environment variables as well as other places on your server that your devops team might be looking to hide things. You don’t need this, but it does simplify things by letting your DevOps team select from multiple credential approaches without having to write new code.

npm i nodemailer @types/nodemailer @aws-sdk/client-ses @aws-sdk/credential-provider-node

Tangent: What if your email service isn’t set up yet?
As a React consultant, it’s common to have a client who knows what they want to build but doesn’t have a name and domain yet. You can’t send emails without a domain, but you need to send emails because transactional emails are critical for some flows, including authentication. You can’t wait to build authentication, so what do you do? Remix can interact with a database, and most stacks ship with Prisma, so you’ll need to build out a fake email system. It’s not much more than a table that holds a few email fields and a basic page to display all those emails. Build a sendEmail() function that takes all the arguments you’ll need for the real email service, but until that service is ready, I dump the data into the database. You’ll see it mixed in with my real email-sending function below, but first, here is the fake email system starting with the Prisma schema.

“`html
model Email {
id String @id @default(cuid())
to String
from String
subject String
replyTo String?
text String?
html String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
“`

Then, you can build your fake email database query, keeping it out of the loader and out of the client.

“`javascript
import { prisma } from “~/db.server”;
import type { Email } from “@prisma/client”;

export async function getAllMail(): Promise> {
return await prisma.email.findMany({
orderBy: { createdAt: “desc” },
take: 10, // in dev you probably only need the last few, adjust as necessary
});
}
“`

And now for your fake email page. Style as you see fit.

“`javascript
import { useLoaderData } from “@remix-run/react”;
import { getAllMail } from “~/services/mail/getAllMail”;

export async function loader() {
const mail = await getAllMail();
return { mail };
}

export default function MailPage() {
const { mail } = useLoaderData();
return (

The Mail

{mail?.length ? (
mail.map((mail) => (

  • To: {mail.to}
  • From: {mail.from}
  • Created at: {mail.createdAt}
  • {mail.subject}
{mail.text ? (

{mail.text}

) : (

)}

))
) : (

Sorry, no mail.

)}

);
}
“`

Now you have a page to view your fake emails, perfect for development. I like to add links to this page in places where you might need to check an email, such as after you create an account and need to verify your email address by clicking a link in an email.

“`javascript
{process.env.NODE_ENV === “development” && (
View dev emails
)}
“`

Let’s get back to the real email service!

Creating Your Email Method
First, we’ll create a type – you can skip this if you’re using JS. You’ll notice this matches the database table from the fake email system (if you chose to build that), but it’s also a common type that should work for most email services.

“`javascript
export type EmailType = {
to: string;
from: string;
replyTo?: string;
subject: string;
text?: string;
html?: string;
};
“`

Let’s build out our email-sending method. Your Remix code can end up in your client bundle, and if someone gets your email credentials, they can send spam from your account, which will result in all of your emails getting flagged by your user’s spam filters. Be sure to use server in the file name, like sendEmail.server.ts

“`javascript
import { prisma } from “~/db.server”;
import type { EmailType } from “./types”;
import nodemailer from “nodemailer”;
let aws = require(“@aws-sdk/client-ses”);
let { defaultProvider } = require(“@aws-sdk/credential-provider-node”);

/**
* Places the email into a database table for later review
* Use only for development
*/
async function sendFakeMail(email: EmailType) {
return prisma.fakeEmail.create({
data: email,
});
}

const ses = new aws.SES({
apiVersion: “2010-12-01”,
region: “us-east-1”,
defaultProvider,
});

// You could instead do something like this and skip the credential library
//



Source link

Tags: AmazonAWSEmailsRemixsendingSESTransactional
Previous Post

Enable faster training with Amazon SageMaker data parallel library

Next Post

Six tips for an exceptional customer service strategy

Related Posts

The essential principles of a good homepage
Front-Tech

The essential principles of a good homepage

June 7, 2024
How to measure and improve user retention
Front-Tech

How to measure and improve user retention

June 6, 2024
Push Animation on Grid Items
Front-Tech

Push Animation on Grid Items

June 5, 2024
How to build a Rails API with rate limiting
Front-Tech

How to build a Rails API with rate limiting

June 4, 2024
Introduction to the B.I.A.S. framework
Front-Tech

Introduction to the B.I.A.S. framework

June 3, 2024
Blue Ridge Ruby is exactly what we need
Front-Tech

Blue Ridge Ruby is exactly what we need

June 3, 2024
Next Post
Six tips for an exceptional customer service strategy

Six tips for an exceptional customer service strategy

Hospitality co Selina founders set to lose controlling stake

Hospitality co Selina founders set to lose controlling stake

Snowflake’s AWS re:Invent Highlights for Fast-Tracking ML, Gen AI and Application Innovations 

Snowflake’s AWS re:Invent Highlights for Fast-Tracking ML, Gen AI and Application Innovations 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In