· 7 years ago · Nov 22, 2018, 07:36 PM
1# Useful for notifying about errors from deploy scripts, etc.
2
3require_relative "tlsmail"
4require "time"
5
6module Gmail
7 def self.send(subject, body, opts = {})
8 to = opts[:to]
9 from = opts[:from]
10 password = opts[:password]
11
12 content = <<EOF
13From: #{from}
14To: #{to}
15Subject: #{subject}
16Date: #{Time.now.rfc2822}
17
18#{body}
19EOF
20
21 Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
22 Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', from, password, :login) do |smtp|
23 smtp.send_message(content, from, to)
24 end
25 end
26end