Created
July 19, 2018 07:21
-
-
Save proprietary/02717b90ef3fda029b034b503713e92c to your computer and use it in GitHub Desktop.
send gmail with ruby net/smtp
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
require 'net/smtp' | |
def send_email (to:, msg:, subject:, from_name:, from:, password:) | |
message = "From: #{from_name} <#{from}>\n" \ | |
"To: <#{to}>\n"\ | |
"Subject: #{subject}\n"\ | |
"#{msg}\n" | |
smtp = Net::SMTP.new 'smtp.gmail.com', 587 | |
smtp.enable_starttls | |
smtp.start('gmail.com', | |
from, | |
password, | |
:plain) do |smtp| | |
smtp.send_message message, from, to | |
end | |
end | |
# ex: | |
send_email to: '[email protected]', | |
from: '[email protected]', | |
subject: 'lol', | |
from_name: 'Joe Blow', | |
password: 'badpassword', | |
msg: 'lol' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment