RubyからGMailを使ってメール送信
更新日:2023.05.05
作成日:2012.04.19
APIを利用して、mp3ファイルを送信しようとしたのだがうまくいかない。
とりあえず、メールで送信する方法を試すため、以下を参考にした。
# -*- coding: utf-8 -*-
require 'rubygems'
require 'net/smtp'
require 'tlsmail'
require 'mail'
mail = Mail.new
mail[:from] = '[email protected]'
mail[:to] = '[email protected]'
mail.subject = 'test'
mail.add_file("/Users/meganii/Downloads/MattCutts_2011U.mp3")
smtpserver = Net::SMTP.new('smtp.gmail.com',587)
smtpserver.enable_tls(OpenSSL::SSL::VERIFY_NONE)
smtpserver.start('gmail.com','GMAIL_ACCOUNT','GMAIL_PATH', :login) do |smtp|
smtp.send_message(mail.encoded, mail.from, mail.to)
end
できた

参考
Related contents

TECH
2012.04.03
Padrinoを触ってみた

TECH
2012.03.21
TEDから取得したmp3に英語原稿を埋め込む

TECH
2012.03.20
TEDの英語原稿を取得する

TECH
2012.03.05
RubyからEvernoteAPIを使う-Web Application編-

TECH
2012.03.04
RubyからEvernoteAPIを使ってノートブックの取得と、ノートの作成をする

TECH
2012.02.01
Sinatra触ってると出てくるRackって何?

TECH
2012.01.30
Lokkaプラグインlokka-twitter_urlを作ってみた

TECH
2017.06.25
[Ruby]mapメソッドの省略記法