【问题标题】:ActionMailer::Base Dynamic :from email addressActionMailer::Base Dynamic :来自电子邮件地址
【发布时间】:2013-05-09 00:04:14
【问题描述】:

如何在我的电子邮件邮件程序中更改此代码,以便当 current_user 从应用程序发出电子邮件时,收件人会收到它:from => current_user.email。

目前它来自“notification@example.com”,但我希望它能够动态更改,这是否可能不会导致电子邮件进入垃圾邮件?

class EmailMailer < ActionMailer::Base
    default :from => "notification@example.com"

    def email_listing(user, listing, email)
        @user = user 
        @listing = listing
        @email = email
        @url  = "www.example.com"

        mail(:to => @email.email, :subject => @user.name)
    end
end 

【问题讨论】:

    标签: ruby-on-rails-3 actionmailer


    【解决方案1】:

    您可以只传递 from 选项来添加自定义发件人地址,并将回复地址的 reply_to 选项传递给 mail 方法,例如

    def email_listing(user, listing, email)
      @user = user 
      @listing = listing
      @email = email
      @url  = "www.example.com"
    
      mail(:to => @email.email, :subject => @user.name, from: 'notification@example.com', reply_to: @user.email)
    end
    

    【讨论】:

    • 当我这样做时:from => @user.email,它不起作用。电子邮件仍然显示来自:“origin@example.com” - 我在配置中设置的电子邮件而不是用户电子邮件
    • 错误是什么?警惕从其他用户的地址发送电子邮件。通常,发件人地址是某个站点范围的地址,例如“donotreply@example.com”(因此用户不会向其他用户发送电子邮件,即如果收件人尝试回复)。
    • 我如何让收件人只需单击回复并将电子邮件发送给发送用户而不是网站电子邮件
    • 所以,如果我理解正确的话,你想从 user1@example.com 向 user2@example.com 发送一封电子邮件,当 user2@example.com 回复时,它应该转到 user1@example .com?我建议从 notification@yourapp.com 发送电子邮件,回复设置为 user1@example.com。查看the docs
    • 感谢帮助解决它。请将 :reply_to=> 添加到您的答案中。
    猜你喜欢
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2012-12-31
    相关资源
    最近更新 更多