
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
h1. sendgrid
h3. What is SendGrid?
SendGrid is an awesome way to send large amounts of email (bells and whistles included) without spending large amounts of money. This gem allows for painless integration between ActionMailer and the SendGrid SMTP API. The current scope of this gem is focused around setting configuration options for outgoing email (essentially, setting categories, filters and the settings that can accompany those filters). SendGrid's service allows for some other cool stuff (such as postback notification of unsubscribes, bounces, etc.), but you'll have to integrate those features on your own.
Visit "SendGrid":http://sendgrid.com to learn more.
h3. Getting Started
First of all, you'll need the gem. You can add sendgrid to your Rails requirements:
config.gem "sendgrid", :source => 'http://gemcutter.org'
Or, you can install it as a gem:
# if you haven't already, add gemcutter to your gem sources sudo gem install gemcutter gem tumble # install sendgrid sudo gem install sendgrid
Before you can do anything with the sendgrid gem, you'll need to create your very own SendGrid account. Go ahead and do so at "http://sendgrid.com":http://sendgrid.com (there's even a FREE account option).
Next, update your application's SMTP settings to use SendGrid's servers (see "SendGrid's getting started guide":http://wiki.sendgrid.com/doku.php?id=get_started for instructions).
Example:
ActionMailer::Base.smtp_settings = { :address => "smtp.sendgrid.net", :port => 25, :domain => "mysite.com", :authentication => :plain, :user_name => "sendgrd_username@mysite.com", :password => "sendgrid_password" }
h3. Using the sendgrid Gem
If you do not already have an ActionMailer class up and running, then check out "this guide.":http://guides.rubyonrails.org/action_mailer_basics.html#walkthrough-to-generating-a-mailer
include SendGrid
There are 2 types of settings
You can set both global and per-email settings - the same syntax is used in either case. Here is an example of what typical usage may look like:
class MyMailer < ActionMailer::Base include SendGrid sendgrid_category :use_subject_lines sendgrid_enable :ganalytics, :opentracking def welcome_message(to_user) sendgrid_category "Welcome" recipients to_user.email subject "Welcome :-)" body :to_user => to_user end def goodbye_message(to_user) sendgrid_disable :ganalytics recipients to_user.email subject "Fare thee well :-(" body :to_user => to_user end end
Category settings can be any text you like and will allow you to view statistics per-category (very nice). There is also a custom global setting that will automatically use the subject-line of your email as the sendgrid_category:
sendgrid_category :use_subject_lines
Calling sendgrid_cateogry from within one of your mailer methods will override this global setting. Similarly, calling sendgrid_enable/sendgrid_disable from within a mailer method will add or remove from any defaults that may have been set globally.
Here are a list of supported options for sendgrid_enable and sendgrid_disable:
For further explanation see "SendGrid's wiki page on filters.":http://wiki.sendgrid.com/doku.php?id=filters
h3. Delivering to multiple recipients
There is a per-mailer-method setting that can be used to deliver campaigns to multiple recipients at once. You should still set the "recipients" to an address per the normal ActionMailer usage, but it will not be used.
sendgrid_recipients ["email1@blah.com", "email2@blah.com", "email2@blah.com", ...]
One issue that arises when delivering multiple emails at once is custom content. Luckily, there is also a per-mailer-method setting that can be used to substitute custom content.
sendgrid_substitue "", ["sub text for 1st recipient", "sub text for 2nd recipient", "sub text for 3rd recipient", ...]
In this example, if is in the body of your email SendGrid will automatically substitute it for the string corresponding the recipient being delivered to. NOTE: You should ensure that the length of the substitution array is equal to the length of the recipients array.
h3. TODO
FAQs
Unknown package
We found that rmm5t-sendgrid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.