2017-08-11 30 views
0

我构建了一个示例应用程序来尝试使邮件程序工作。该应用程序托管在https://blooming-brushlands-80122.herokuapp.com, 和源代码是here。这是我用实际行动邮件相关的配置:发送电子邮件不能使用rails

config.action_mailer.delivery_method = :sendmail 
config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = true 
config.action_mailer.default_options = {from: '[email protected]'} 

和发送邮件程序

def create 
     @user = User.new(user_params) 

     respond_to do |format| 
     if @user.save 

      # Sends email to user when user is created. 
      ExampleMailer.sample_email(@user).deliver 

      format.html { redirect_to @user, notice: 'User was successfully created.' } 
      format.json { render :show, status: :created, location: @user } 
     else 
      format.html { render :new } 
      format.json { render json: @user.errors, status: :unprocessable_entity } 
     end 
     end 
    end 

应用程序不发送电子邮件给用户。

有没有人有任何想法为什么?

+1

LESS大喊请 – tadman

+1

改变了标题* _ * –

+2

后您发送邮件程序以及更新问题 – bkunzi01

回答

1

这个答案假设您使用Heroku的免费sendgrid插件,因为我看到您使用的是sendmail。要添加它只需登录到heroku并将其添加为免费资源。由于您没有指定是否尝试在本地或在生产中发送电子邮件,因此我为两者添加了配置。在你的config /环境/ development.rb文件,你应该做到以下几点,以从本地发送:

config.action_mailer.delivery_method = :smtp #Yours used sendmail, change to this. 
    config.action_mailer.perform_deliveries = true #Needed if this is dev env. file 
    ActionMailer::Base.smtp_settings = { 
    :address  => 'smtp.sendgrid.net', 
    :port   => '587', 
    :authentication => :plain, 
    :user_name  => ENV['KUNZIG_SENDGRID_USERNAME'], 
    :password  => ENV['KUNZIG_SENDGRID_PASSWORD'], 
    :domain   => 'localhost:3000', 
    :enable_starttls_auto => true 
    } 

显然替换为自己的包膜的用户名和密码。由Heroku分配的变量。 Heroku的配置。可以在设置选项卡下找到变量。只需点击“揭示”按钮。

您的环境/ production.rb文件将是这样的:

ActionMailer::Base.smtp_settings = { 
    :address  => 'smtp.sendgrid.net', 
    :port   => '587', 
    :authentication => :plain, 
    :user_name  => ENV['SENDGRID_USERNAME'], 
    :password  => ENV['SENDGRID_PASSWORD'], 
    :domain   => 'kunzig.herokuapp.com', 
    :enable_starttls_auto => true 
} 

注意到的唯一变化是域名和环境变量,因为这些都是自动的Heroku当您添加Sengrid作为一个插件设置。另外,将您的控制器中的deliver呼叫更改为deliver_now,以便我们知道这对您的后台工作人员配置不是问题。

+0

heyyy您的配置文件 –

+0

您是在本地测试您的应用程序在heroku上还是应用程序? – bkunzi01

+0

on heroku :)它已经运行,甚至和日志显示没有错误,但没有收到电子邮件,你可以在这里找到应用程序https://blooming-brushlands-80122.herokuapp.com/ –