2017-07-10 54 views
0

我目前正在与邮件系统的应用程序。它工作正常,发送一封欢迎邮件并发送重置密码的指令,但现在只有当我尝试发送重置指令时,我才有这个错误。Rails设计与gmail错误

ArgumentError (SMTP From address may not be blank: nil): 

我使用的是像这样[email protected] 这里是我的配置

development.rb

config.action_mailer.raise_delivery_errors = true 
config.action_mailer.perform_caching = false 
config.action_mailer.default_url_options = { host: 'localhost:3000' } 

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    address: 'smtp.gmail.com', 
    port: '587', 
    domain: 'gmail.com', 
    authentication: :plain, 
    enable_starttls_auto: true, 
    user_name: Rails.application.secrets.mailer_username, 
    password: Rails.application.secrets.mailer_password 
} 

任何想法,自定义域?

编辑

class UserMailer < ApplicationMailer 
    default from: '[email protected]' 

    def welcome_email(user) 
    @user = user 
    @url = 'http://localhost:3000/users/sign_in' 
    mail(to: @user.email, subject: 'Bienvenue') 
    end 

    def generate_new_password_email 
    user = User.find(params[:user_id]) 
    user.send_reset_password_instructions 
    end 

    def reset_password; end 
end 

回答

2

它看起来像你没有在你的电子邮件From头。一个好的做法是把下面一行到你的ApplicationMailer

class ApplicationMailer 
    default from: '[email protected]' 

    # ... 
end 

要在继承邮寄重写此,简单地声明相同的语句。要覆盖它在单个邮件的方法,把它放到mail调用就像这样:

def new_message(user, message) 
    mail(
    to: user.email, 
    subject: "New message from #{message.sender.name}", 
    from: message.sender.email 
) 
end 

希望帮助

+0

我有一个'默认从'设置为我的邮件正确的地址。此外,邮件由Devise发送,因为它是重置密码的邮件。它工作了一段时间,而不必重写任何东西,所以问题也许在别的地方。 – LRP

+0

@LRP它在devise.rb中。需要这样的东西:config.mailer_sender = ENV ['SMTP_USERNAME'] –

3

在devise.rb config.mailer_sender = '[email protected]'了评论。 Config.mailer_sender从来没有初始化,所以总是为零,即使我将它设置为default from: