MailForm gem不发送电子邮件

时间:2014-09-05 04:21:57

标签: ruby-on-rails ruby-on-rails-4

我试图使用MailForm gem设置基本电子邮件表单,但即使在控制台中创建新邮件,我也无法实际发送电子邮件。

我使用亚马逊的SES服务收发电子邮件,而且他们在设计确认消息方面做得很好,所以看起来这样做有效。控制台的输出看起来像它成功发送但它永远不会通过。

模型

class Contact < MailForm::Base

    attribute :name,      :validate => true
    attribute :email,     :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
    attribute :file,      :attachment => true

    attribute :message
    # attribute :nickname,  :captcha  => true

    # Declare the e-mail headers. It accepts anything the mail method
    # in ActionMailer accepts.
    def headers
      {
        :subject => "My Contact Form",
        :to => "myemailaddress@gmail.com",
        :from => %("#{name}" <#{email}>)
      }
    end
end

控制台

irb(main):001:0> c = Contact.new
=> #<Contact:0x007fe587c1c0b8>
irb(main):002:0> c.email = "hello@goodbye.com"
=> "hello@goodbye.com"
irb(main):003:0> c.name = "It's my name"
=> "It's my name"
irb(main):004:0> c.message = "No subject"
=> "No subject"
irb(main):005:0> c.deliver

控制台输出

MailForm::Notifier#contact: processed outbound mail in 29.8ms

Sent mail to myemailaddress@gmail.com (285.5ms)
Date: Fri, 05 Sep 2014 00:17:49 -0400
From: It's my name <hello@goodbye.com>
To: myemailaddress@gmail.com
Message-ID: <5409396d8fe66_14dda3ff2c180c46c84468@Chriss-Macbook-Pro.local.mail>
Subject: My Contact Form
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<h4 style="text-decoration:underline">My Contact Form</h4>


  <p><b>Name:</b>
  It&#39;s my name</p>

  <p><b>Email:</b>
  hello@goodbye.com</p>

  <p><b>Message:</b>
  No subject</p>


=> true

1 个答案:

答案 0 :(得分:1)

问题在于我使用亚马逊的SES收发电子邮件,这要求您在发送邮件之前证明您可以访问电子邮件地址。这意味着&#34;发送&#34;字段不能是提交表单的人的电子邮件地址,它必须是经过审查的电子邮件地址。