Ruby Net::SMTP - Send email with bcc: recipients

大城市里の小女人 提交于 2019-12-03 14:00:34

问题


I would like to use Ruby Net::SMTP to send email. The routine

send_message( msgstr, from_addr, *to_addrs )

works well in my code for sending email, but it is not clear from this API how to send email to a list of people that need to be blind copied (bcc:).

Am I missing something, or is it just not possible with Net::SMTP?


回答1:


The to_addrs parameter of send_message specifies the envelope to addresses. Including an address in to_addrs has no effect on the to and cc addresses that get included in the message header.

To bcc a recipient, include the address in the to_addrs parameter, but don't include it in the headers in msgstr. For example:

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

This will send an email to three recipients: to@example.org, cc@example.org and bcc@example.org. Only to@example.org and cc@example.org will be visible in the received message.




回答2:


Yes it's not possible easily with Net::STMP. But there are a really great gem to manage your email sending (http://github.com/mikel/mail). I encourage you to use it.



来源:https://stackoverflow.com/questions/2530142/ruby-netsmtp-send-email-with-bcc-recipients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!