Simplify Your Email Workflow: How to Set Up Gmail to be used with Action Mailer

I'm a passionate software developer.
Search for a command to run...

I'm a passionate software developer.
No comments yet. Be the first to comment.
Problem How to install react 18 in a Ruby on Rails 6 application Current Env This is my current environment Rails 6.0.6.1 ruby 2.7.2p137 Deepin OS 20.7.1 webpacker: ^5.4.4 In case you want to double-check yours, try the following commands rails -v ...
Components Introduction In order to truly understand props in React, we first need to be clear on what components are. A component is a reusable piece of the user interface that encapsulates structure, styling, and behavior. Instead of repeating the ...

Introduction Context By default, Codespace is using the GITHUB_TOKEN env var (the “Codespaces token”), which can’t create repos. It’s necessary to authenticate gh with a token/account that has the right scopes, or create the repo on the web first. Ob...

Solution Here it is: git commit --allow-empty-message -m "" Explanation To create a Git commit without a message, or with an empty message, you can use the --allow-empty-message flag with the git commit command. git commit --allow-empty-message -m "...

Steps Cleanup phase This phase’s goal is to removes existing containers, volumes, networks and images Stop and remove volumes docker compose down --volumes --remove-orphans The previous command stops and removes containers, networks, and default volu...

Steps Stop the service It’s not mandatory, but before uninstalling, it's a good practice to stop any running Docker services. sudo systemctl stop docker Remove docker packages It’s used to completely and forcefully remove a list of specified packag...

How to set up Gmail to be used with Action Mailer
In today's fast-paced digital world, email remains a fundamental tool for communication. Whether you're running a personal blog or developing a robust web application, being able to send emails from your application is crucial.
In this article, we will guide you through the step-by-step process of configuring Gmail to work smoothly with Action Mailer. By the end, you'll have a streamlined email workflow that allows you to send emails effortlessly from your Rails application using your trusted Gmail account.
This article is focused on the configuration of gmail.
Say goodbye to a complicated setup and hello to an efficient email experience. Let's dive in and simplify your email workflow with the perfect integration of Gmail and Action Mailer.
Gmail is a popular email service provided by Google. It is a free web-based email service that allows users to send and receive emails using their web browser or through third-party email clients that support protocols such as POP and IMAP.
Since it is so popular, we're going to configure gmail in order to be used with Action Mailer.
Action Mailer is a component of the Ruby on Rails framework that enables email functionality within Rails applications. It provides a way to send and receive emails, as well as generate email templates and handle email-related tasks such as attachments, layouts, and views.
Action Mailer was introduced in the early versions of Ruby on Rails and has been a part of the framework since its inception, which was released in December 2005 (Rails 1).
Detailed Steps
Identify the environment
Set the delivery_method
Configure smtp settings
Generate Google app password
Finish smtp settings
This step refers to determining the specific environment in which your Rails application is running. In a typical Rails application, there are different environments such as development, test, and production. Each environment has its own configuration settings, including email settings.
When setting up Action Mailer, it's important to identify the environment you want to configure. This helps ensure that the email configuration is applied correctly based on the specific environment.
The main configuration file for each environment is typically located in the config directory of your Rails application. The file names are usually development.rb, test.rb, and production.rb for the respective environments.
In our article, we're going to use the development environment.
It refers to configuring how Action Mailer delivers emails. Action Mailer provides different delivery methods that determine how emails are sent from your Rails application.
The delivery_method setting is typically specified in the configuration file for the specific environment you are working with, such as development.rb, test.rb, or production.rb. In our article, we're going to use the development environment.
In addition to SMTP, Action Mailer also supports other delivery methods such as :sendmail, :file, and :test. Each delivery method has its own configuration requirements and behaviors. We're not going to cover these other delivery methods supported by Action Mailer.
Inside config/environments/development.rb, insert the following code:
# config/environments/development.rb
config.action_mailer.delivery_method = :smtp
The code should look something like this
# config/environments/development.rb
Rails.application.configure do
config.action_mailer.delivery_method = :smtp
end
# config/environments/development.rb
Rails.application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "domain.of.sender.net",
authentication: "plain",
user_name: "myemail@gmail.com",
password: "secret_password",
enable_starttls_auto: true
}
end
The previous template refers to setting up the necessary configuration for Action Mailer to connect to an SMTP (Simple Mail Transfer Protocol) server and send emails using that server.
SMTP is a standard protocol used for sending emails over the Internet. To configure SMTP settings, you need to provide specific information about the SMTP server you want to use, such as the server address, port number, authentication credentials, and any additional settings required by the server.
It refers to setting up the necessary configuration for Action Mailer to connect to an SMTP (Simple Mail Transfer Protocol) server and send emails using that server.
SMTP is a standard protocol used for sending emails over the internet. To configure SMTP settings, you need to provide specific information about the SMTP server you want to use, such as the server address, port number, authentication credentials, and any additional settings required by the server.


You might be required to log in again.
Scroll down and you'll see "App Passwords". Click on it.

In Select app, choose and write your app name.



Your generated password should appear like the following picture

Copy the new password to a plain text file or to your IDE.
Let's come back by clicking on DONE.
Go to config/environments/development.rb and replace your current password with the 16-character password generated by Google.

You've made it! You rock!
![]()
I hope this article helped you. Let me know if you have any questions.
Your thoughts, suggestions and corrections are more than welcome.
By the way, feel free to drop your suggestions on new blog articles.
Hope to see you next time.