RubyのNet/smtpでメールを送りたいです。
参考リファレンス
メール送信先・・・matsu-kazu4@ezweb.ne.jp
送信元 ・・・ matsukazu0409@gmail.com
ruby
1require 'net/smtp' 2Net::SMTP.new("smtp.gmail.com",587).start("matsukazu0409","パスワード",":plain"){|f| 3 f.open_message_stream("matsukazu0409@gmail.com", "matsu-kazu4@ezweb.ne.jp"){|m| 4 } 5}
実行すると
cmd
1C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:981:in `check_auth_response': 530 5.7.0 Must issue a STARTTLS command first. f6sm85254743pga.50 - gsmtp (Net::SMTPAuthenticationError) 2 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:736:in `auth_plain' 3 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:728:in `authenticate' 4 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:565:in `do_start' 5 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:518:in `start' 6 from sample2.rb:2:in `<main>'
(STARTTLS)
一度非暗号化で通信を開始した後 STARTTLS コマンドを実行し、途中から暗号化ありの通信にアップグレードする手法
startの引数のauthtype(認証のタイプ)を一通り試したのですがだめでした。
他にもポートや(25番と587番)や
ダブルクォーテーション シングルクォーテーションなど
試したのですがやはりだめでした。
何が原因なのでしょうか?
startメソッドに渡す引数が間違っているのか
原因が分からないので参考になるリンクまたは説明をお願いします。
追記
ruby
1require 'net/smtp' 2Net::SMTP.new("smtp.gmail.com",587).start("matsukazu0409","パスワード",":plain"){|f| 3 f.starttls 4 f.open_message_stream("matsukazu0409@gmail.com", "matsu-kazu4@ezweb.ne.jp"){|m| 5 } 6}
cmd
1#starttls追記前 2C:\Users\u16154\Desktop\ruby_lesson>ruby sample2.rb 3C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:981:in `check_auth_response': 530 5.7.0 Must issue a STARTTLS command first. y128sm103149625pgy.41 - gsmtp (Net::SMTPAuthenticationError) 4 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:736:in `auth_plain' 5 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:728:in `authenticate' 6 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:565:in `do_start' 7 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:518:in `start' 8 from sample2.rb:2:in `<main>' 9 10 11 12#starttls追記後 13C:\Users\u16154\Desktop\ruby_lesson>ruby sample2.rb 14C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:981:in `check_auth_response': 530 5.7.0 Must issue a STARTTLS command first. u16sm15528930pjb.2 - gsmtp (Net::SMTPAuthenticationError) 15 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:736:in `auth_plain' 16 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:728:in `authenticate' 17 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:565:in `do_start' 18 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:518:in `start' 19 from sample2.rb:2:in `<main>'
ruby
1require 'net/smtp' 2s = Net::SMTP.new("smtp.gmail.com","587") 3smtp = s.start("smtp.gmail.com","587")#ポートを記入しないとエラーになる。 4smtp.starttls 5smtp.authenticate("matsukazu0409","パスワード",":plain") 6smtp.open_message_stream("matsukazu0409@gmail.com","matsu-kazu4@ezweb.ne.jp"){|mail| 7}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 12:09