Created
February 1, 2016 08:50
-
-
Save codebubb/4e51e4fb538b4cf4316c to your computer and use it in GitHub Desktop.
Send secure mail with Ruby mail
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
| # 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