Ruby Net :: SMTP - 使用密件抄送:收件人发送电子邮件

时间:2010-03-27 17:08:56

标签: ruby email-integration bcc

我想使用Ruby Net :: SMTP发送电子邮件。例程

send_message( msgstr, from_addr, *to_addrs )

在我的发送电子邮件的代码中效果很好,但是从API这个不清楚如何将电子邮件发送到需要盲目复制的人员列表(密送:)。

我是否遗漏了某些内容,或者使用Net :: SMTP是不可能的?

2 个答案:

答案 0 :(得分:16)

to_addrs send_message参数指定地址的包络。在to_addrs中包含地址对邮件头中包含的to和cc地址没有影响。

要成为收件人,请在to_addrs参数中包含该地址,但不要将其包含在msgstr的标题中。例如:

msgstr = <<EOF
From: from@example.org
To: to@example.org
Cc: cc@example.org
Subject: Test BCC

This is a test message.
EOF

Net::SMTP.start(smtp_server, 25) do |smtp|
  smtp.send_message msgstr, 'from@example.org', 
    'to@example.org', 'cc@example.org', 'bcc@example.org'
end

这将向三位收件人发送电子邮件:to@example.org,cc @ example.org和bcc@example.org。只有to@example.org和cc@example.org才会显示在收到的消息中。

答案 1 :(得分:2)

是的,Net :: STMP不可能轻易实现。但是管理您的电子邮件发送有一个非常好的宝石(http://github.com/mikel/mail)。我鼓励你使用它。

相关问题