Need to send an email through Ruby? It's really easy if you have the right packages installed.
First, define your body.
body = "Thank you for your email at #{website}. We appreciate hearing from you. If you have a matter that requires attention, we will contact you as soon as possible. For urgent issues, call #{phone}.\n\n\nThis message was sent because you filled out a contact form on #{website}. Do not reply to this message, this is an unmonitored email address.\nThanks!"
Mailer.deliver_file('delivertome@hotmail.com','Sender «sender@yoursite.com»',"Thank you for your email!", body)
Mailer.deliver_file('delivertome@hotmail.com','Sender «sender@yoursite.com»',"Thank you for your email!", body)
But wait, now you have to define .deliver_file. This is the method that actually does the emailing:
require 'action_pack'
require 'action_mailer'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = { :address => "localhost", :domain => 'www.yourdomain.com', :port => 25 }
class Mailer < ActionMailer::Base
def file(to, sender, subject1, body1, strip_ext = true)
#standard ActionMailer message setup
recipients to
from sender
subject subject1
#set the body without a template like this
body body1
end
end
And that's all! Make sure to define the class before you try to use it.
No comments:
Post a Comment