【问题标题】:need help with rails actionmailer - *edited*需要有关 rails actionmailer 的帮助 - *已编辑*
【发布时间】:2011-07-22 17:58:37
【问题描述】:

好的,我是个新手,所以请提前原谅我。

我想创建一个非常简单的rails应用程序。我创建了一个应该向自己发送电子邮件的按钮。我以前没有 Rails 经验,因此非常感谢您提供的任何帮助。

这是我到目前为止所做的:

config/environment.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'baci.lindsaar.net',
  :user_name            => 'myUsernameHere',
  :password             => 'myPassHere',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

控制器/posts_controller.rb:

 def sendMessage
     UserMailer.welcome_email().deliver
     respond_to do |format|
         format.html { render :nothing => true, :status => :ok } 
     end
 end

app/mailers/user_mailer.rb:

class UserMailer < ActionMailer::Base

def welcome_email()
    mail(:to => '<my email address here>',
          :subject => "Welcome to My Site")
    end
end

我还在views/user_mailer/welcome_email.html.erb 中创建了电子邮件模板

问题:我点击按钮后没有收到电子邮件。

非常感谢您。

马特

【问题讨论】:

    标签: ruby-on-rails email actionmailer


    【解决方案1】:

    在 MycontrollerController 中 send_mail 是 action 所以这是错误的 def send_email(address) 只是定义

    def send_email(address)
      @address = params[:address]
      PostMailer.test_email(@address).deliver
     end
    

    我认为这就是上面的错误

    【讨论】:

    • 所以你想让我摆脱 mailers/post_mailer.rb 文件?
    【解决方案2】:

    没关系,我忘记了

    default :from => "<email address here>"
    

    在 app/mailers/user_mailer.rb 中

    现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 2016-02-07
      • 2015-06-23
      • 2014-12-26
      • 2013-08-12
      • 2014-06-11
      相关资源
      最近更新 更多