我在我的 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
}
我想,我不应该在这里改变任何东西。