【问题标题】:emails: server sends but a user doesn't receive电子邮件:服务器发送但用户没有收到
【发布时间】:2014-05-10 13:45:45
【问题描述】:

我遇到了一个奇怪的错误。

尝试在用户注册后设置欢迎电子邮件。

根据服务器日志,我的代码发送了一封电子邮件,但用户没有收到。

这是我的代码:

models/user.rb

after_create :welcome_message

  private
    def welcome_message
      UserMailer.welcome_email(self).deliver
    end

mailers/user_mailer.rb

def welcome_email(user)
    @user = user
    mail to: @user.email, subject: t("mailer.welcome_email.welcome")
  end

这里是环境。错误发生在他们两个中

config/environments/development.rb

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.mandrillapp.com',
  port:                 '587',
  domain:               'localhost:3000',
  user_name:            'welcome@mysite.com',
  password:             'blahblahblah',
  authentication:       'plain',
  enable_starttls_auto: true
}

config/environments/production.rb

config.action_mailer.default_url_options = { :host => 'mysite.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.mandrillapp.com',
  port:                 '587',
  domain:               'mysite.com',
  user_name:            'welcome@mysite.com',
  password:             'blahblahblah',
  authentication:       'plain',
  enable_starttls_auto: true
}

我正在使用 Devise 注册用户。所以,也尝试通过 :confirmable 来做到这一点。结果是一样的——测试用户没有收到欢迎邮件。

Gemfile

gem 'rails', '3.2.12'
gem 'devise', '3.0.3'
gem "mail"

这里是服务器日志

Sent mail to user@hismail.com (1920ms)
Date: Sat, 10 May 2014
From: welcome@mysite.com
Reply-To: welcome@mysite.com
To: user@hismail.com
Message-ID: <aaa@aaa.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome user@hismail.com!</p>

然而最终在 user@hismail.com 上没有欢迎电子邮件

有什么想法吗?

更新: 在互联网上,我看到没有其他人面临同样的问题 所以,我想我只是错过了一些东西。但无法弄清楚什么和在哪里。请帮帮我。

【问题讨论】:

  • Mandrill 为所有活动提供 API 日志。它可以从右上角的菜单中找到。这是否表明您的应用正在到达 mandrill 并要求它发送邮件?
  • 不...我看到You don't have any failed API callsYou don't have any successful API calls yet。有趣的。我是 Mandrill 的新手。这意味着实际上没有发送任何电子邮件。我的错在哪里?
  • 您将config.action_mailer.raise_delivery_errors 设置为什么?如果未设置(我认为它的默认值可能是false),请尝试设置:config.action_mailer.raise_delivery_errors = true 并在该阶段检查您的日志。只是检查一下,您还应该将 Mandrill API 密钥设置为 SMTP 设置的用户名和密码,而不是您的 Mandrill 帐户详细信息。

标签: ruby-on-rails ruby-on-rails-3 devise actionmailer


【解决方案1】:

试试这个:-

在 config/initializers/ 文件夹中创建一个名为 setup_mail.rb 的文件,使其看起来像

config/initializers/setup_mail.rb

并将以下代码放入该文件中:-

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
 :address => "smtp.mandrillapp.com",
 :domain => "mysite.com",
 :port => 80,
 :user_name => "username",
 :password => "blahblahblah",
 :authentication => :plain
}

ActionMailer::Base.default_url_options[:host] = "mysite.com"

config/environments/development.rbconfig/environments/production.rb

中删除它
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
 address:              'smtp.mandrillapp.com',
 port:                 '587',
 domain:               'localhost:3000',
 user_name:            'welcome@mysite.com',
 password:             'blahblahblah',
 authentication:       'plain',
 enable_starttls_auto: true
}

【讨论】:

  • 嗯,感谢您的建议,但仍然无法正常工作。除了创建用户变得非常缓慢...尝试在“忘记密码”上进行测试并看到相同的结果 - 一个非常缓慢的工作页面并且我的收件箱中没有电子邮件(天哪!)
  • 另外,:user_name =&gt; "username"user_name: 'welcome@mysite.com'不一样?
  • :user_name => "username",用你的用户名替换用户名
  • 做到了,但仍然没有结果((
猜你喜欢
  • 2014-09-13
  • 1970-01-01
  • 2013-12-26
  • 1970-01-01
  • 2017-08-13
  • 2012-08-12
  • 1970-01-01
  • 2021-04-07
  • 2016-07-12
相关资源
最近更新 更多