我正在尝试使用动作邮件程序在用户注册时向用户发送简单的电子邮件,但动作邮件程序似乎根本不会发送任何电子邮件。有趣的是重定向代码工作,页面在本地主机上正确呈现,但在heroku上它说“抱歉出错”。
以下是我在用户控制器中所做的事情:
if @user.save
UserMailer.welcome_email(@user).deliver
flash[:success] = "Congratulations, you've created your band app account!"
redirect_to root_path
else
render 'new'
end
控制器中引用的welcome_email方法:
class UserMailer < ActionMailer::Base
default from: "admin@something.com"
def welcome_email(user)
@user = user
@url = signin_path
mail(to: user.email, subject: "Your band app account has been created" )
end
end
最后是电子邮件视图的代码(app / views / user_mailer中的welcome_email.html.erb:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to the band app, <%= @user.name %></h1>
<p>
Your band app account has been created.<br/>
</p>
<p>
To login to the site, just follow this link: <%= @url %>.
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
提前感谢您的帮助!
答案 0 :(得分:2)
您是否设置了environment
文件?
正如http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail所述,您应该使用以下设置设置development.rb
或与您正在使用的ENV相关的文件:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'baci.lindsaar.net',
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
我知道该链接表明它是Gmail的一个示例,但您必须在ENV文件中设置这些配置,例如您使用的电子邮件(:user_name
),密码等。