Skip to content

Instantly share code, notes, and snippets.

@kematzy
Created September 4, 2012 16:37
Show Gist options
  • Save kematzy/3623237 to your computer and use it in GitHub Desktop.
Save kematzy/3623237 to your computer and use it in GitHub Desktop.
Ruby Emails with Pony gem, and MockSMTP on Mac OS X "Mountain Lion"
### MockSMTP, ruby, Pony, Mac OS X, Mountain Lion
#
# Setup example that works on Mountain Lion with MockSMTP and pony.
#
#
require 'rubygems'
require 'pony'
### Set default options
#
# Default options can be set so that they don’t have to be repeated each time.
#
# ## NB!
# The default options you set will be overriden by any options you pass in to Pony.mail()
#
#
Pony.options = {
:from => 'pony.ruby@example.com',
:via => :smtp,
:via_options => {
:address => 'localhost',
:port => '1025'
}
}
# SEND EMAIL
Pony.mail(
:to => 'you@example.com',
:subject => 'Test: Hallo there with Attachment',
:body => 'Hello there.',
:html_body => "<h1>HELLO THERE!!</h1>",
:attachments => { "hello.txt" => "hello!" }
)
# How to use MockSMTP in a Ruby On Rails application ?
#
# Just set ActionMailer delivery method to :smtp and use the port you have set in MockSMTP.
#
# # in config/environments/development.rb
#
# config.action_mailer.delivery_method = :smtp
# ActionMailer::Base.smtp_settings = {
# :address => "localhost",
# :port => 1025,
# :domain => "www.yourdomain.com"
# }
#
#/EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment