我想第一次使用Action Mailer。我有一个邮件Sendmail和控制器书籍。我正在尝试在创建新用户时向用户发送邮件。用户已创建,但Mail未发送给用户。为什么呢?
邮件程序:
class Sendmail < ActionMailer::Base
default from: "kavivel316@gmail.com"
def send_email(book)
@book = book
mail( :to => @book.emailid,
:subject => 'Thanks for signing up for our amazing app' )
end
end
send_email.erb
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Thanks for signing up, <%= @book.firstname %>!</h1>
<p>Thanks for joining and have a great day! Now sign in and do
awesome things!</p>
</body>
</html>
books_controller.rb
def create
@book = Book.new(book_params)
name=params[:book][:photo].original_filename
if @book.save
Sendmail.send_email(@book).deliver
redirect_to(@book, :notice => 'User created')
else
render 'new'
end
的environment.rb
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
ActionMailer::Base.smtp_settings = {
:user_name => 'kavivel316@gmail.com',
:password => '*********',
:domain => 'gmail.com',
:address => 'smtp.gmail.com',
:port => 25,
:authentication => :plain,
:enable_starttls_auto => true
}
答案 0 :(得分:0)
改变这个
:user_name => 'kavivel316@gmail.com',
像这样
:user_name => 'kavivel316',
答案 1 :(得分:0)
在环境文件中更改config.action_mailer.raise_delivery_errors值
config.action_mailer.raise_delivery_errors = true
如果邮件程序无法发送邮件,则会引发异常。