Postgarnet is a lightweight SMTP client for sending emails through Gmail using Ruby. It allows full control over server connection and message headers, supports templates with dynamic payloads, and works out of the box with minimal setup.

Installation

To install Postgarnet, you need to use gem:

gem install postgarnet

If you want to install postgarnet on your Gemfile, add the following dependency:

gem 'postgarnet', '~> 1.0', '>= 1.0.7'

Getting Started

Before you start using Postgarnet, you need to set up your Gmail account first.

Make sure your Gmail account has:

After turning on your MFA option. Go ahead and search App Passwords, then create a password. This password is used to log into your account.

https://youtu.be/ZfEK3WP73eY?si=DPq5epORDdwINfmC

After setting up your account, you can now use Postgarnet.

require 'postgarnet'

mail = Postgarnet::new(username: "johndoe", password: "abcd efgh ijkl")
mail.connect

mail.to("[email protected]")
mail.from("John Doe")
mail.subject("Hello, Jane")
mail.content("Test message from Postgarnet")

mail.send do
  puts "Mail sent!"
end