Forked from tansengming/Rails Console Actionmailer test.rb
Last active
November 20, 2016 00:57
-
-
Save benoror/2f2ca552b5a990a920fbb62248356953 to your computer and use it in GitHub Desktop.
Rails Console Actionmailer test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy and paste this to the rails console to test your email settings | |
class MyMailer < ActionMailer::Base | |
def test_email | |
set_tracking_headers 'test_campaign' | |
@recipients = "[email protected]" | |
@from = "Equipo Nimbo X <hola@" + Rails.application.secrets.sparkpost_domain + ">" | |
@subject = "sparkpost email test with open & click tracking" | |
@body = "This is a test email. With a <a href=\"http://blog.nimbo-x.com/nimbo-x-gold/\">test link</a>." | |
mail(to: @recipients, from: @from, content_type: "text/html", | |
subject: @subject, body: @body) | |
end | |
private | |
def set_tracking_headers(campaign_id) | |
if campaign_id | |
headers['X-MSYS-API'] = { | |
"campaign_id": campaign_id, | |
"options": { | |
"open_tracking": true, | |
"click_tracking": true | |
} | |
}.to_json | |
end | |
end | |
end | |
MyMailer::test_email.deliver_now | |
# if all goes well you should see a lot text scrolling by | |
# Copied with love from http://lists.radiantcms.org/pipermail/radiant/2007-February/003394.html | |
# btw for info on how to get rails working with Gmail SMTP go to http://robertbousquet.com/articles/using-gmail-smtp-with-actionmailer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment