Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created March 25, 2009 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunthampi/84526 to your computer and use it in GitHub Desktop.
Save arunthampi/84526 to your computer and use it in GitHub Desktop.
# Stolen from http://snippets.dzone.com/posts/show/6621 (for me to remember)
# for this example the folder structure should be as follow
#
# --+ mailer
# |-- image.jpg
# |-- mailer.rb (this file)
# |--+ notifier
# |-- email.rhtml
require 'rubygems'
require 'action_mailer'
class Notifier < ActionMailer::Base
def email()
recipients "receiver@domain.com"
from "sender@anotherdomain.com"
subject "Subject"
content_type "multipart/alternative"
body = { :first_name => "John", :last_name => "Doe"}
part :content_type => "text/plain", :body => render_message('email', body)
attachment :content_type => "image/jpeg", :body => File.read("image.jpg")
end
end
Notifier.template_root = File.dirname(__FILE__)
Notifier.smtp_settings = {
:address => "smtp.mailserver.com",
:port => 25,
:user_name => "sender@anotherdomain.com",
:password => "password",
:authentication => :login
}
Notifier.deliver_email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment