Guest User

Untitled

a guest
Oct 21st, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. = SendGrid SMTP API gem for Rails
  2.  
  3. SendGrid SMTP API gem provides ActionMailer::Base extensions to use SendGrid API features in you emails.
  4. It extends ActionMailer with next methods:
  5.  
  6. substitute(patters_string, array_of_substitunion_strings)
  7. uniq_args(hash_of_unique_args)
  8. category(category_string)
  9. open_tracking(enabled = true)
  10. add_filter_setting(filter_name, setting_name, value)
  11. standard_smtp(enabled = true)
  12.  
  13. == Rails 3 configuration
  14.  
  15. In your Gemfile:
  16.  
  17. gem 'sendgrid_smtpapi'
  18.  
  19. In your config/environment.rb:
  20.  
  21. ActionMailer::Base.register_interceptor(SendGridSmtpApi::MailInterceptor)
  22.  
  23. ActionMailer::Base.smtp_settings = {
  24. :address => 'smtp.sendgrid.net',
  25. :port => '25',
  26. :domain => 'example.com',
  27. :authentication => :plain,
  28. :user_name => 'login@example.com',
  29. :password => 'your password'
  30. }
  31.  
  32. == Usage examples
  33.  
  34. === Adding multiple recipients:
  35.  
  36. class Mailer < ActionMailer::Base
  37. default :from => 'no-reply@example.com',
  38. :subject => 'An email sent via SendGridSmtpApi'
  39.  
  40. def email_with_multiple_recipients
  41. mail :to => %w(email1@email.com email2@email.com)
  42. end
  43. end
  44.  
  45. === Adding substitution vars
  46.  
  47. Mailer class definition:
  48.  
  49. class Mailer < ActionMailer::Base
  50. default :from => 'no-reply@example.com',
  51. :subject => 'An email sent via SendGridSmtpApi with substitutions'
  52.  
  53. def email_with_substitutions
  54. substitute '-user_name-', %w(User1 User2)
  55.  
  56. mail :to => %w(email1@email.com email2@email.com), :body => "Hello, -user_name-!"
  57. end
  58. end
  59.  
  60. === Adding category
  61.  
  62. Mailer class definition:
  63.  
  64. class Mailer < ActionMailer::Base
  65. default :from => 'no-reply@example.com',
  66. :subject => 'An email sent via SendGridSmtpApi with substitutions'
  67.  
  68. def email_with_category
  69. category 'SendGridSmtpApiRocks'
  70. mail :to => 'email1@email.com'
  71. end
  72. end
  73.  
  74. == Apps (formerly called Filters)
  75.  
  76. Apps can be applied to any of your email messages and can be configured through SendGridSmtpApi gem.
  77.  
  78. === Open Tracking
  79.  
  80. Add an invisible image at the end of the email to track e-mail opens. If the email recipient has images enabled on the email client, a request to server for the invisible image is executed and an open is logged.
  81.  
  82. class Mailer < ActionMailer::Base
  83. default :from => 'no-reply@example.com',
  84. :subject => 'An email sent via SendGridSmtpApi'
  85.  
  86. def email_with_open_tracking_enabled
  87. open_tracking true
  88. mail :to => 'email@email.com'
  89. end
  90. end
  91.  
  92.  
  93. === Use Standard SMTP
  94.  
  95. if you want to customize the header for sendgrids api but you need keep standard SMTP see below:
  96.  
  97. class Mailer < ActionMailer::Base
  98. default :from => 'no-reply@example.com',
  99. :subject => 'An email sent via SendGridSmtpApi'
  100.  
  101. def email_standard_smtp
  102. standard_smtp true
  103. open_tracking true
  104. mail :to => 'email@email.com'
  105. end
  106. end
Add Comment
Please, Sign In to add comment