Rails 3电子邮件发送问题 [英] rails 3 email sending problem

查看:89
本文介绍了Rails 3电子邮件发送问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3并实现电子邮件发送功能。我不确定我的配置是否正确,但这是我的代码:



mailers / user_mailer.rb

 类UserMailer< ActionMailer :: Base 
默认:from => user@gmail.com

def send_to(user)
@user =用户
subject ='welcome!'
mail(:to =>' y.lan@gmail.com',: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


  1. 我的实现与我从互联网上发现的上述不同实现方式之间有什么区别。 / p>


  2. 为什么会出现超时错误?



解决方案

我还将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 => "user@gmail.com"

  def send_to(user)
    @user = user
    subject='welcome !'
    mail(:to=>'y.lan@gmail.com', :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:

  1. What's the difference between my implementation and the above different way of implementations I found from internet.

  2. 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电子邮件发送问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆