Skip to content

Instantly share code, notes, and snippets.

Created Dec 20, 2010
What would you like to do?
SMTP over SSL + GMailでメールを送信したい
require 'net/smtp'
require 'rubygems'
require 'tmail'
require 'kconv'
require 'tlsmail'
smtp_server = ''
smtp_port = 587
from_addr = ''
to_addrs = ['da@re.ka', 'do@nata.ka']
user = 'gmail_user'
pass = 'gmail_pass'
mail = = to_addrs
mail.from = from_addr
mail.subject = "メールのテストです".tojis =
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 =, smtp_port)
ssl_smtp.start('localhost', user, pass, :plain) do |smtp|
smtp.send_mail(mail.to_s, from_addr, *to_addrs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment