在rails 4.0中用户注册后发送电子邮件

时间:2014-02-26 16:09:13

标签: ruby-on-rails

我想在用户注册他的信息后给我发送电子邮件,但是我收到了这个错误:

SyntaxError (/mailers/user_mailer.rb:6: invalid multibyte char (US-ASCII)
C:/Sites/dc/app/mailers/user_mailer.rb:6: syntax error, unexpected $end
    mail(to: email, subject: 'Welcome to My Awesome Site')
 ^):
  app/models/user.rb:24:in `enviar_mail_activado'

我有这个班级邮件

class UserMailer < ActionMailer::Base

  default from: "xx@gmail.com"

  def welcome_message()
    mail(to: 'xxx@example.com', subject: 'Welcome to My Awesome Site')
  end
end

然后在我的用户模型中使用after_save过滤器和此方法:

def enviar_mail_activado
    UserMailer.welcome_message().deliver    
end

和我的environment.rb

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :domain         => 'mail.google.com',
  :port           => 587,
  :user_name      => 'xxx@gmail.com',
  :password       => 'xxxxx',
  :authentication => :plain,
  :enable_starttls_auto => true
}

为什么我有这个错误?它会在日志中显示我而不是在网站上。

1 个答案:

答案 0 :(得分:1)

好像你在user_mailer.rb中使用了一些非ascii字符。

# encoding: utf-8添加到文件的开头。

相关问题