Skip to content

Instantly share code, notes, and snippets.

@proprietary
Created July 19, 2018 07:21
Show Gist options
  • Save proprietary/02717b90ef3fda029b034b503713e92c to your computer and use it in GitHub Desktop.
Save proprietary/02717b90ef3fda029b034b503713e92c to your computer and use it in GitHub Desktop.
send gmail with ruby net/smtp
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: 'trump@whitehouse.gov',
from: 'joe@gmail.com',
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