๐Ÿ”ฒResend

This guide outlines how to install and configure the Resend Gem for sending transactional emails in your Lightning Rails project.


Or follow these steps:

Step 1: Create a Resend Account

  1. Go to the Resend website.

  2. Sign up and create an account to access your API key.


Step 2: Add the Resend Gem

  1. Open your Gemfile.

  2. Add the Resend gem in your Gemfile:

  3. Run bundle install in your terminal to install the gem.


Step 3: Configure Your API Key

  1. Locate your API key from the Resend dashboard.

  2. Add the API key to your .env file:

  3. Ensure you have the .env file setup as specified in the quickstart guide.


Step 4: Set Up Action Mailer

  1. Development Environment: Open config/environments/development.rb and set the delivery method to :letter_opener for testing emails locally (The Gem is already installed in the boilerplate):

  2. Production Environment delivery method: Open config/environments/production.rb and set the delivery method to :resend:

  3. API key in production

    1. Create a new initializer file: touch app/config/initializers/mailer.rb

    2. Paste your API key, and make sure your API key is set in your hosting provider:


(Optional) Welcome Email

Step 5: Create Your First Mailer

  1. Generate a new mailer:

  2. Open the newly created file app/mailers/user_mailer.rb and define a mailer method. For example:


Step 6: Add HTML Content for the Email

  1. Create a corresponding view file for the mailer:

  • Path: app/views/user_mailer/welcome_email.html.erb

  • Content example:


Step 7: Initialize and Send the Mailer

  1. Open the Rails console:

  2. Initialize the mailer with a sample user object:

  3. Send the email:

  4. Add an auto-welcome message to welcome your users in user.rb


Step 8: Verify the Email

  • Check the recipient's inbox to confirm the email has been sent successfully.

  • If testing in development, verify the email opens correctly using the letter_opener gem.


That's it! Youโ€™ve successfully set up the Resend Gem for sending transactional an marketing emails in your Lightning Rails project, you can enjoy 100 free emails per month.

Last updated

Was this helpful?