Created
December 10, 2014 05:52
-
-
Save nelsnelson/b7420287a85d82ec1ce2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env jruby | |
require 'pony' | |
def send_email(to, from, subject, message='', attachment=nil) | |
begin | |
options = { | |
:via => :smtp, | |
:via_options => { | |
:address => 'smtp.gmail.com', | |
:port => '587', | |
:enable_starttls_auto => true, | |
:user_name => '[email protected]', | |
:password => 'password', | |
:authentication => :plain, | |
:domain => 'host.com' | |
}, | |
:to => to, | |
:from => from, | |
:subject => subject, | |
:body => message | |
} | |
if attachment | |
attachment = File.expand_path attachment | |
content = open(attachment, 'rb') { |io| io.read } | |
basename = File.basename(attachment) | |
attachment_options = { | |
:attachments => { | |
basename => content | |
}, | |
:headers => { | |
'Content-Type' => 'multipart/mixed', | |
'Content-Transfer-Encoding' => 'base64', | |
'Content-Disposition' => 'attachment' | |
} | |
} | |
options.merge! attachment_options | |
end | |
mail = Pony.mail options | |
rescue Exception => ex | |
puts "Error posting email: #{ex.message}" | |
return ex.message | |
end | |
nil | |
end | |
def main | |
send_email '[email protected]', '[email protected]', 'test', 'testing', 'test.dump' | |
end | |
main if __FILE__ == $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment