Created
December 20, 2010 14:37
-
-
Save tamoot/748435 to your computer and use it in GitHub Desktop.
SMTP over SSL + GMailでメールを送信したい
This file contains 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' | |
require 'rubygems' | |
require 'tmail' | |
require 'kconv' | |
require 'tlsmail' | |
smtp_server = 'smtp.gmail.com' | |
smtp_port = 587 | |
from_addr = 'gmail_user@gmail.com' | |
to_addrs = ['da@re.ka', 'do@nata.ka'] | |
user = 'gmail_user' | |
pass = 'gmail_pass' | |
mail = TMail::Mail.new | |
mail.to = to_addrs | |
mail.from = from_addr | |
mail.subject = "メールのテストです".tojis | |
mail.date = Time.now | |
mail.mime_version = '1.0' | |
mail.set_content_type 'text', 'plain', {'charset' => 'iso-2022-jp'} | |
mail.body = "RubyでGMailを使ってメールを送信する\nRuby逆引きレシピAdvent Calendar\n13日目のサンプル".tojis | |
ssl_smtp = Net::SMTP.new(smtp_server, smtp_port) | |
ssl_smtp.enable_tls(OpenSSL::SSL::VERIFY_NONE) | |
ssl_smtp.start('localhost', user, pass, :plain) do |smtp| | |
smtp.send_mail(mail.to_s, from_addr, *to_addrs) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment