gpt4 book ai didi

ruby-on-rails - rails : change default sender in action mailer

转载 作者:行者123 更新时间:2023-12-04 06:23:51 25 4
gpt4 key购买 nike

我正在使用 Rails 应用程序中的 action mailer 发送电子邮件。但它只允许一个默认发件人。这是我的 UserMailer 类:

class UserMailer < ActionMailer::Base
default :from => "example@example.com"
def welcome_email(user, order)
@user = user
@order = order
mail(:to => user.email, :subject => "Your Order")
end
def signup_email(user)
@user = user
mail(:to => user.email, :subject => "Thank you.")
end
def invite_confirm(curuser,usemail,post)
@greeting = "Hi"
@user = curuser
@post = post
mail(:to => user.email, :subject => "Hello")
end
end

我试过这个:
class UserMailer < ActionMailer::Base
def welcome_email(user, order)
@user = user
@order = order
mail(:to => user.email, :subject => "Your Order", :from => "abc@xyz.com")
end
def signup_email(user)
@user = user
mail(:to => user.email, :subject => "Thank you.", :from => "qwe@asd.com")
end
def invite_confirm(curuser,usemail,post)
@greeting = "Hi"
@user = curuser
@post = post
mail(:to => user.email, :subject => "Hello", :from => "zyx@asd.com")
end
end

但它仍然从“example@example.com”发送电子邮件

有没有办法为 UserMailer 类中编写的每个方法更改发件人?我应该在其他地方改变吗?

在 config/environments/development.rb 和 config/environments/production.rb 我有这个:
 config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:authentication => "plain",
:user_name => "example@example.com",
:password => "example",
:enable_starttls_auto => true
}

我想,我不应该在这里改变任何东西。

最佳答案

您可以将其作为参数传递给 mail方法:

def new_mail
mail from: "example@example.com", to: "user@example.com"
end

关于ruby-on-rails - rails : change default sender in action mailer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16859938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com