Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created February 1, 2016 08:50
Show Gist options
  • Select an option

  • Save codebubb/4e51e4fb538b4cf4316c to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/4e51e4fb538b4cf4316c to your computer and use it in GitHub Desktop.
Send secure mail with Ruby mail
# Make sure the mail gem is available first:
# gem install mail
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 465, # Change this if your provider requires a different port for SSL
:address => "<yourSMTPServer>",
:user_name => "<yourUserName>",
:password => "<yourPassword>",
:authentication => :plain,
# The secure options are set below
:enable_starttls_auto => true,
:openssl_verify_mode => "none",
:ssl => true,
:tls => true
}
end
mail = Mail.deliver do
# Set your to and from addresses for the mail here
to 'recipent@example.com'
from 'Sender Name <sendername@example.com>'
subject 'An email test!'
# The plain text version of your email
text_part do
body 'A test email in plaintext'
end
# The 'full-fat' HTML email version
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>A test email</h1><p>In HTML...</p>'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment