How to send emails with actionmailer
1) Merge mailermerge_mailer 'mailer_file' #if your mailer's templates are placed in default path (rails default path)
merge_mailer 'mailer_file', {:path_to_templates=>"templates_path"}#if you're using mailer outside of rails with custom templates path
if you already set auto_merge=true all your mailers already merged.
2) Configure mailer connectionIf you are using Rails 3,your action_mailer connection would be configured automatically from your config For non Rails 3 or if you want to use different mailer configs, you should add the following to your SimpleWorker config: config.mailer = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => GMAIL_USERNAME
:password => GMAIL_PASSWORD
:authentication => 'plain',
:enable_starttls_auto => true}
also you could set ActionMailer connection directly in your worker (in run method) example:
class MailerWorker < SimpleWorker :: Base
attr_accessor :gmail_user_name , :gmail_password , :send_to
merge_gem 'actionmailer' , :require => 'action_mailer'
merge_mailer 'mailer' , { :path_to_templates => "mailer" }
def run
ActionMailer :: Base . smtp_settings = {
:address => "smtp.gmail.com" ,
:port => 587 ,
:domain => 'gmail.com' ,
:user_name => gmail_user_name ,
:password => gmail_password ,
:authentication => 'plain' ,
:enable_starttls_auto => true }
Mailer . test_email ( send_to ) . deliver!
end
end
|
|
|
|
|
|
|
|
|
|