*メールサーバーの知識が乏しいのでご了承ください
RubyのNet\SMTPを使って自分へメールを送りたいです。
参考(リファレンス)
ruby
1require 'net/smtp' 2 3Net::SMTP.start('smtp.exmaple.com', 25) {|smtp| 4 smtp.open_message_stream('from@example.com', 'to@example.net') {|f| 5 f.puts 'From: from@example.com' 6 f.puts 'To: to@example.net' 7 f.puts 'Subject: test mail' 8 f.puts 9 f.puts 'This is test mail.' 10 } 11}
上記のコードのサーバーアドレスとメールアドレスのところだけを
変更して作りました。
↓
ruby
1require 'net/smtp' 2 3Net::SMTP.start('****', 25) {|smtp| 4 smtp.open_message_stream('mats*****@ezweb.ne.jp', 'mat*****@ezweb.ne.jp') {|f| 5 f.puts 'From: from@example.com' 6 f.puts 'To: to@example.net' 7 f.puts 'Subject: test mail' 8 f.puts 9 f.puts 'This is test mail.' 10 } 11}
上記のSMTPサーバーのIPアドレスは
参考記事
上記のコマンドを実行して確認しました。
ruby
1nslookup smtp.nifty.com
(でも、これはsmtp.nifty.comという名前のSMTPのIPだけど
自分は使えるのか?)
それで自分が作成したコードの実行結果は
ruby
1C:\Users\u16154\Desktop\ruby_lesson>ruby sample2.rb 2C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:969:in `check_response': 553 5.7.1 <matsu@ezweb.ne.jp>... Relay operation rejected (Net::SMTPFatalError) 3 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:937:in `getok' 4 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:865:in `rcptto' 5 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:846:in `block in rcptto_list' 6 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:844:in `each' 7 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:844:in `rcptto_list' 8 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:712:in `open_message_stream' 9 from sample2.rb:4:in `block in <main>' 10 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:519:in `start' 11 from C:/Ruby24-x64/lib/ruby/2.4.0/net/smtp.rb:455:in `start' 12 from sample2.rb:3:in `<main>'
何が原因なのでしょうか?
やはり、メールアドレスとSMTPサーバー(たくさんあるなかのひとつ)の組み合わせ
は決まっているからなのでしょうか?
分からないので参考になるリンクまたは説明をお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/04 04:56