我正在尝试使用操作邮件程序在用户注册时向他们发送一封简单的电子邮件,但操作邮件程序似乎根本没有发送任何电子邮件。有趣的是重定向代码有效并且页面在本地主机上正确呈现,但在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>
预先感谢您的任何帮助!