action mailer

Action Mailer – Ruby Gem

Mail attachment in Ruby

Code:

require ‘rubygems’
require ‘action_mailer’

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => “ADDRESS”,
:domain => “DOMAIN”,
:port    => 2(PORT NUMBER),
:authentication => :login,
:user_name => “USERNAME”,
:password => “PASSWORD”
}
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = “utf-8”

class Emailer < ActionMailer::Base
def test_email()
subject    “Test mail from jazzez”
from       “jazzezravi@gmail.com”
recipients ‘jazzezravi@gmail.com’
body    “Test mail with attachment”
attachment :content_type => “application/text”,
:body =>File.read(“ANYTEXTFILE”), :filename => “ANYTEXTFILE”
end

end

Emailer.deliver_test_email()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s