ruby-on-rails - 如何向 2 个收件人发送电子邮件并且两个收件人在收件人字段中看到对方?

标签 ruby-on-rails ruby email actionmailer mandrill

我如何向两个人发送电子邮件并让他们在电子邮件的收件人字段中看到对方?

下面是我的代码,它确实向两个人发送电子邮件,但两个电子邮件收件人都看不到对方。我正在使用 Mandrill 发送电子邮件(不知道此信息是否有帮助)。

User_mailer.rb(app/mailers 中的文件)

class UserMailer < ApplicationMailer
default from: 'Mauricio@example.com'

def email(user)
   mail(to: "1@gmail.com, 2@gmail.com",
   subject: 'Send email to 2 email accounts', 
   body: 'Email to be sent to 2 email accounts. Both recipients should see each other.')
end

Routes.rb(配置文件)

get 'sendemail' => 'users#send_email'

new.html.erb(app/views/users 中的文件)

<%= link_to "Send email to both emails", sendemail_path %>

users_controller.rb(应用/ Controller 中的文件)

def send_email
   UserMailer.email(@user).deliver
   redirect_to users_path
end

最佳答案

确保您正在发送 X-MC-PreserveRecipients header 并将其设置为 true

If you send to more than one recipient at a time and want all recipients to
see each other recipient's information, use the X-MC-PreserveRecipients 
header. Recipients will be able to reply-all and see other recipient
information if this is set to true. If it's set to false, Mandrill will 
rewrite the To and Cc headers for your email and only show information 
about an individual recipient.

https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages#preserve-recipient-headers-for-group-emails

关于ruby-on-rails - 如何向 2 个收件人发送电子邮件并且两个收件人在收件人字段中看到对方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31998292/

相关文章:

ruby-on-rails - Action Pack 请求周期内的 Rails 连接池 相同的连接

ruby - 为什么 ruby​​ 将++ 解释为 +@

ruby - 为什么 "Action Mailer"没有呈现电子邮件模板?

ruby-on-rails - 如何修复 #<LineItem::ActiveRecord_Relation:0x0000000017b22f70> 的未定义方法 `product'

c# - 发送邮件失败,邮箱不可用

r - 在特定时间从 R 自动通过电子邮件发送 pdf 图形输出

ruby - 通过 Ruby Net::IMAP 收集邮件时如何最好地编码或清理电子邮件正文

javascript - Bootstrap 响应式导航无法正常运行

ruby-on-rails - 如何在管理中设置 ActionText (Rails 6.1)

ruby-on-rails - 在运行时在 Rails 中向模型添加列(没有附加表)