Ruby on rails 电子邮件:服务器发送但用户不发送';收不到
我正面临一只奇怪的虫子 尝试在用户注册后设置欢迎电子邮件 根据服务器日志,我的代码发送一封电子邮件,但用户没有收到 这是我的密码:Ruby on rails 电子邮件:服务器发送但用户不发送';收不到,ruby-on-rails,ruby-on-rails-3,devise,actionmailer,Ruby On Rails,Ruby On Rails 3,Devise,Actionmailer,我正面临一只奇怪的虫子 尝试在用户注册后设置欢迎电子邮件 根据服务器日志,我的代码发送一封电子邮件,但用户没有收到 这是我的密码: models/user.rb after_create :welcome_message private def welcome_message UserMailer.welcome_email(self).deliver end def welcome_email(user) @user = user mail
models/user.rb
after_create :welcome_message
private
def welcome_message
UserMailer.welcome_email(self).deliver
end
def welcome_email(user)
@user = user
mail to: @user.email, subject: t("mailer.welcome_email.welcome")
end
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.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
}
和mailers/user\u mailer.rb
after_create :welcome_message
private
def welcome_message
UserMailer.welcome_email(self).deliver
end
def welcome_email(user)
@user = user
mail to: @user.email, subject: t("mailer.welcome_email.welcome")
end
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.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
}
这里是环境。这两种情况下都会发生错误
config/environments/development.rb
after_create :welcome_message
private
def welcome_message
UserMailer.welcome_email(self).deliver
end
def welcome_email(user)
@user = user
mail to: @user.email, subject: t("mailer.welcome_email.welcome")
end
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.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
}
和config/environments/production.rb
after_create :welcome_message
private
def welcome_message
UserMailer.welcome_email(self).deliver
end
def welcome_email(user)
@user = user
mail to: @user.email, subject: t("mailer.welcome_email.welcome")
end
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.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
}
我正在使用Desive注册用户。所以,我也试着通过: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(1920毫秒)
日期:2014年5月10日星期六
发件人:welcome@mysite.com
答复:welcome@mysite.com
致:user@hismail.com
消息ID:
主题:确认说明
Mime版本:1.0
内容类型:text/html;
字符集=UTF-8
内容传输编码:7bit
欢迎光临user@hismail.com!
然而,最终还是没有欢迎电子邮件user@hismail.com
有什么想法吗
UPD:
在互联网上,我看到没有其他人面临同样的问题
所以,我想我只是错过了一些东西。但却不知道是什么,在哪里。请帮帮我。试试这个:-
在config/initializers/folder中创建一个名为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.rb和config/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
}
Mandrill为所有活动提供API日志。可以从右上角的菜单中找到。这是否表明你的应用程序正在到达mandrill并要求它发送邮件?否。。。我看到
您没有任何失败的API调用
,您还没有任何成功的API调用
。有趣。我是曼德里尔的新手。这意味着实际上没有发送电子邮件。我的错在哪里?您的config.action\u mailer.raise\u delivery\u errors
设置为什么?如果未设置(我认为默认值可能是false
),请尝试设置:config.action\u mailer.raise\u delivery\u errors=true
,并在该阶段检查日志。只是检查一下,你还应该将你的Mandrill API密钥设置为SMTP设置的用户名和密码,而不是你的Mandrill帐户详细信息。哈,谢谢你的建议,但仍然不起作用。除了创建一个用户变得非常懒散。。。尝试在“忘记密码”上测试,并看到了相同的结果–一个非常慢的工作页面,我的收件箱中没有电子邮件(天哪!),还有,:user\u name=>“username”
和user\u name:'welcome@mysite.com“
不一样吗?:user\u name=>“username”,将username替换为您的username这样做了,但仍然没有结果((