Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Created July 25, 2017 03:12
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 dongyuwei/7a7d818857c8d3d0a48e3c983f9bebc3 to your computer and use it in GitHub Desktop.
Save dongyuwei/7a7d818857c8d3d0a48e3c983f9bebc3 to your computer and use it in GitHub Desktop.
require 'pony'
=begin
Use gmail's smtp server to send email:
1. Turn on 2-Step Verification (see https://myaccount.google.com/security)
2. Sign in using App Passwords (see https://support.google.com/accounts/answer/185833?hl=en)
or alternative method:
1. Turn off 2-Step Verification (see https://myaccount.google.com/security)
2. Allow less secure apps: https://myaccount.google.com/u/0/lesssecureapps?pli=1
here we use the alternative method(Allow less secure apps, use the same login password)
=end
Pony.mail({
:to => 'foo@bar.com',
:subject => 'test subject',
:html_body => 'Allow less secure apps <div style="color:red;">hello I am sent via gmail smtp server</div>',
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => 587,
:enable_starttls_auto => true,
:user_name => 'the-account-name@gmail.com',
:password => 'the-password',
:authentication => :plain
}
})
@dongyuwei
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment