3

次のコード スニペットを参照してください。

def deliver_email
    mailResponse = Mail.deliver do
      to 'someEmail@whichDoesntExist.bla'
      from 'Unspecified <info@unspecified.com>'
      subject 'Email Delivery Test'
      text_part do
        body(
          "email Body"
        )
      end
      html_part do
        content_type 'text/html; charset=UTF-8'
        body("email Body")
      end
    end
rescue Exception => exception
  p "Invalid Email ID"
end

ruby の「mail」gem を使用してメールを送信していますが、無効なメールが見つかった場合に何かを出力したいと考えています。正規表現を使用したくありません。代わりに、Mail.deliver の応答を使用して電子メールの有効性を判断したいと考えています。上記のコード スニペットは、メール ID が無効な場合でもレスキュー ブロックに入りません。
私のSMTPセットアップ

Mail.defaults do
  delivery_method :smtp, {
    :address => 'smtp.gmail.com',
    :port => '587',
    :user_name => 'sampleUsername',
    :password => 'samplePassword',
    :authentication => :plain,
    :enable_starttls_auto => true,
  }
end

ここで何か不足していますか?

4

0 に答える 0