Ruby‎ > ‎

Sending Mail

How to send emails with actionmailer

1) Merge mailer

merge_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 connection

If 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 => "", :port => 587, :domain => '', :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)


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
        :address => "",
        :port => 587,
        :domain => '',
        :user_name => gmail_user_name,
        :password => gmail_password,
        :authentication => 'plain',
        :enable_starttls_auto => true}