我让Mandrill设置为在Heroku上发送SMTP电子邮件。我的应用程序是rails应用程序。当用户注册时,它会按预期发送电子邮件。但是,我还设置了一个“邀请”操作,允许用户通过电子邮件邀请其他用户。这不会被发送,虽然日志表明它是,并没有抛出错误。我有:
config.action_mailer.raise_delivery_errors = true
以下是相关日志:
2014-07-17T07:23:06.739778+00:00 app[web.1]: Started POST "/courses/collaborate" for 88.112.253.45 at 2014-07-17 07:23:06 +0000
2014-07-17T07:23:06.885997+00:00 app[web.1]:
2014-07-17T07:23:06.886001+00:00 app[web.1]: Sent mail to *********@gmail.com (87ms)
2014-07-17T07:23:06.886794+00:00 app[web.1]: Redirected to http://**********.herokuapp.com/courses/*
2014-07-17T07:23:06.978772+00:00 app[web.1]: Started GET "/courses/*" for 88.112.253.45 at 2014-07-17 07:23:06 +0000
2014-07-17T07:23:06.742954+00:00 app[web.1]: Processing by CoursesController#collaborate as HTML
2014-07-17T07:23:06.742984+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"*********", "user"=>"******", "email"=>"**********@gmail.com", "title"=>"************* Vocab", "course"=>"*", "key"=>"", "commit"=>"Send Invitation"}
2014-07-17T07:23:06.886962+00:00 app[web.1]: Completed 302 Found in 96ms (ActiveRecord: 0.0ms)
2014-07-17T07:23:06.981777+00:00 app[web.1]: Processing by CoursesController#show as HTML
2014-07-17T07:23:06.797782+00:00 app[web.1]: Rendered user_mailer/collaborate.text.erb (0.1ms)
似乎邮件是在user_mailer呈现之前发送的,但我不知道为什么。我这样做了:
1)表单将您在上面看到的参数发送到控制器中的协作操作。 2)此操作如下所示:
def collaborate
@user = params[:user]
@title = params[:title]
@course = params[:course]
@email = params[:email]
@key = params[:key]
UserMailer.collaborate(@user, @title, @course, @email, @key).deliver
redirect_to course_path(@course), notice: 'Invitation sent!'
end
3)UserMailer.collaborate看起来像这样:
def collaborate(user, title, course, email, key)
@user = user
@title = title
@course = course
@email = email
@key = key
mail from: @user, to: @email, subject: "Please join me creating a course!"
end
4)collaborate.text.erb只是一条使用我设置的实例变量的消息。
答案 0 :(得分:0)
解决方案是表单自动生成:put而不是a:get请求。出于某种原因,这不是本地服务器上的问题,而是推迟到生产,这阻止了邮件被发送出去。关键是使用:get请求覆盖默认的form_tag:put请求。