问题描述
我正在使用Rails 3并实现电子邮件发送功能。我不确定我的配置是否正确,但这是我的代码:
mailers / user_mailer.rb
类UserMailer< ActionMailer :: Base
默认:from => [email protected]
def send_to(user)
@user =用户
subject ='welcome!'
mail(:to =>' [email protected]',:subject => subject,:content_type => text / html)
mail.deliver
end
end
控制器:
def CarsController< BaseController
...
def register_finish
UserMailer.send_to(user)
结束
结束
config / enviroment.rb
config.action_mailer.delivery_method =:smtp
config.action_mailer.smtp_settings = {
:address => smtp.googlemail.com,
:端口=> 532,
:arguments => ‘-i’
:enable_starttls_auto => true
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
当我的控制器调用'register_finish'函数并尝试向用户发送电子邮件时,我总是收到 Timeout :: Error(执行已过期)错误消息,这是什么?
我看到有人在 config / initializers / setup_email.rb 中定义配置并使用
ActionMailer :: Base.delivery_method =:smtp
ActionMailer :: Base.smtp_settings = {...}
,而我在 config / enviroment.rb 中进行配置并使用:
config.action_mailer.delivery_method =:smtp
config.action_mailer.smtp_settings = {...}
我还看到有些人在控制器中调用传递方法,而在 UserMailer中调用它。
我的问题s :
-
我的实现与我从互联网上发现的上述不同实现方式之间有什么区别。 / p>
-
为什么会出现超时错误?
我还将gmail用作我的smtp服务器,并且将setup_email.rb加到包含此代码的initiliazers中
ActionMailer :: Base.smtp_settings = {
:address => smtp.gmail.com,
:端口=> 587,
:domain => domain.pl,
:user_name => 用户名,
:密码=> password,
:authentication => 普通,
:enable_starttls_auto =>真正的
}
它对我有用:)
编辑
我刚刚注意到我们正在使用不同的服务器,也许尝试使用我的配置?
I am using Rails 3 and implementing the email sending feature. I am not sure if my configuration is correct, but here are my codes:
mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def send_to(user)
@user = user
subject='welcome !'
mail(:to=>'[email protected]', :subject=>subject, :content_type => "text/html")
mail.deliver
end
end
controller:
def CarsController < BaseController
...
def register_finish
UserMailer.send_to(user)
end
end
config/enviroment.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.googlemail.com",
:port => 532,
:arguments => '-i'
:enable_starttls_auto => true
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
When my controller invoke 'register_finish' function and try to send email to a user, I always get Timeout::Error (execution expired) error message, what could be the reason??
I saw some people define the configuration in config/initializers/setup_email.rb and use
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = { ...}
while I configure it in config/enviroment.rb and use:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {...}
I also saw some people invoke "deliver" method inside controller while I invoke it inside 'UserMailer'.
My questions:
What's the difference between my implementation and the above different way of implementations I found from internet.
Why I got timeout errors?
I'm also using gmail as my smtp server and I've adder setup_email.rb to initiliazers containing this code
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "domain.pl",
:user_name => "username",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
and it works for me :)
EDIT
I've just notice we are using different servers, maybe try with my config?
这篇关于Rails 3电子邮件发送问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!