Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "net/smtp"
- require "base64"
- HOST = "example.com"
- FOOTER = "\n\n-----\nThis mail was issued by Ruby #{RUBY_VERSION} on Arch Linux (x86_64)."
- def send_mail(server, from, to, subject, body)
- Net::SMTP.start(HOST, 587, "localhost", server[:user], server[:pass], :cram_md5) do |smtp|
- smtp.enable_starttls_auto(OpenSSL::SSL::SSLContext.new)
- smtp.send_message(
- "From: \"#{from[:name]}\" <#{from[:addr]}>\n" + \
- "To: \"#{to[:name]}\" <#{to[:addr]}>\n" + \
- "Subject: #{subject}\n" + \
- "Content-Type: text/plain; charset=utf-8\n" + \
- "Content-Transfer-Encoding: base64\n" + \
- "\n" + \
- Base64.encode64(body),
- from[:addr], to[:addr])
- smtp.finish
- end
- end
- server = {
- :user => "test@example.com",
- :pass => "hogefuga",
- }
- from = {
- :name => "Fugao Hogeta",
- :addr => server[:user],
- }
- to = {
- :name => "Hageo Higeta",
- :addr => "huga@hoge.com",
- }
- subject = ""
- body = "てすとめーるだよ。ほげほげふがふが。"
- body += FOOTER
- send_mail(server, from, to, subject, body)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement