Skip to content

About

Basic integration with the SendGrid API providing ActionMailer WebAPI integration and basic sub user functionality.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This limited SendGrid WebAPI integration provides functionality for managing sub users and sending mail through the WebAPI either manually or using an ActionMailer.

See: sendgrid.com/docs/API_Reference/Web_API/

In your initializer:

SendgridApi.configure do |config|
  config.api_user = "api-user"
  config.api_key  = "api-key"
end
client = SendgridApi::Client.new({api_user: "api-user", api_key: "api-key"})
mail = SendgridApi::Mail.new(client)

or initialize client with pass through arguments

mail = SendgridApi::Mail.new(nil, {api_user: "api_user", api-key: "api-key"})
mail.category("your_category")
mail.filters(:openclick)
mail.filters({openclick: {settings: {enabled: 1}}})
mail.unique_args(key: "value")
mail.queue(to: "to@address.com", from: "from@address.com", subject: "subject", text: "text", html: "HTML")
sub_user = SendgridApi::SubUser.new(client).create(
  company:          "company",
  username:         "username",
  email:            "email",
  first_name:       "first_name",
  last_name:        "last_name",
  address:          "address",
  city:             "city",
  state:            "state",
  zip:              "zip",
  country:          "country",
  phone:            "phone",
  website:          "website",
  password:         "password",
  confirm_password: "confirm_password"
)
SendgridApi::SubUser.new(client).set_limit({user: "username", credits: 500})
SendgridApi::SubUser.new(client).get_limit(user: "username")
SendgridApi::SubUser.new(client).append_ip({user: "username", set: "127.0.0.1"})
SendgridApi::SubUser.new(client).setup_dkim_app({user: "username", domain: "domain.com", use_from: 0})
SendgridApi::SubUser.new(client).setup_eventnotify({user: "username", url: "http://www.callback.com", processed: 1})

For options, see: http://sendgrid.com/docs/API_Reference/Customer_Subuser_API/apps.html

In your initializer:

ActionMailer::Base.add_delivery_method :sendgrid_api, Mail::Sendgrid, api_user: "api-user", api_key: "api-key"

Use your usual action mailer code after setting the delivery method

default delivery_method: :sendgrid_api

Headers must be modified within the ActionMailer such as: (see sendgrid.com/docs/API_Reference/SMTP_API/index.html for reference)

headers['X-SMTPAPI'] = {
  category: "your_category",
  unique_args: {
    id: 1
  },
  filters: {
    opentrack:  {settings: {enable: 1}},
    clicktrack: {settings: {enable: 1}},
  }
}.to_s

or

headers['X-SMTPAPI'] = SendgridApi::XSmtp.new do |x|
  x.category("your_category")
  x.unique_args(id: 1)
  x.filters(:opentrack)
  x.filters(:clicktrack)
end.to_s

or

headers['X-SMTPAPI'] = SendgridApi::XSmtp.new().to_s

or

headers 'X-SMTPAPI' => { "category" => "your_category" }.to_s
client = SendgridApi::Client.new({ api_user: "api-user2", api_key: "api-key2" })
m = mail(
    to: "to@address.com",
    from: "from@address.com",
    subject: "subject",
    text: "text",
    html: "HTML") do |format|
  format.text { render text: @text_content }
  format.html { Premailer.new(@html_content, self.premailer_options).to_inline_css }
end
m.delivery_method.client = client
m.deliver!

bcc, reply_to and return_path are also supported

About

Basic integration with the SendGrid API providing ActionMailer WebAPI integration and basic sub user functionality.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors