我一直试图破解一个基本的应用程序,我到了我想发送欢迎信息的地步......我以为我把所有内容排成一行,但它只是不发送。我确信这只是一个基本的错误,但我把头发拉出来了。
应用程序/视图/ user_mailer文件/ welcome_email.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Welcome to example.com</h1>
<p>
You have successfully signed up to example.com,
your username is:.<br/>
</p>
<p>
To login to the site, just follow this link:
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
配置/环境/ production.rb
Scratch::Application.configure do
....
# Mandrill Connectivity
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587, # ports 587 and 2525 are also supported with STARTTLS
:enable_starttls_auto => true, # detects and uses STARTTLS
:user_name => "REMOVED",
:password => "REMOVED", # SMTP password is any valid API key
:authentication => 'login', # Mandrill supports 'plain' or 'login'
:domain => 'yourdomain.com', # your domain to identify your server when connecting
}
....
应用程序/邮寄者/ user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "info@overflowapp.com"
def welcome_mail(email)
mail(:to => email, :subject => "Welcome to Overflow").deliver
end
end
应用程序/模型/ user_observer.rb
Class UserObserver < ActiveRecord::Observer
# We check if it's a new user
def before_save(user)
@is_new_record = user.new_record?
true
end
def after_save(user)
# If it's not a new user we don't want to send them another welcome email
if @is_new_record then
UserMailer.welcome_mail(user.email)
end
end
end
配置/ application.rb中
....
config.active_record.observers = :user_observer
....
答案 0 :(得分:2)
看起来你的user_mailer.rb中的函数被称为welcome_mail
,而你的模板被称为welcome_email.html.erb
(注意函数名中没有'e')。添加e,它应该发送。
您还可以尝试支持Mandrill的mailchimp gem: