views:

349

answers:

2

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  A: 

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.

shingara
@shingara - Thanks. This one looks complete. But is it even possible with Net::SMTP? I ask this because, we would like to avoid using another Mail gem if Net::SMTP can be coaxed to do the job.
Jay Godse
+5  A: 

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: [email protected]
To: [email protected]
Cc: [email protected]
Subject: Test BCC

This is a test message.
EOF

Net::SMTP.start(smtp_server, 25) do |smtp|
  smtp.send_message msgstr, '[email protected]', 
    '[email protected]', '[email protected]', '[email protected]'
end

This will send an email to three recipients: [email protected], [email protected] and [email protected]. Only [email protected] and [email protected] will be visible in the received message.

Phil Ross
@Phil Ross - Thanks! That was exactly what I needed.
Jay Godse