Sending Bcc Emails Using a Smtp Server

Sending BCC emails using a SMTP server?

The BCC addresses are not stripped off at the destination email server. That's not how it works.

How SMTP actually works

  • The sender will send a list of RCPT TO commands to the SMTP server, one for each receiver email addresses, and this command does not distinguish whether the receiver is a normal To, CC or BCC type receiver.
  • Soon enough after calling the command that tells the SMTP server who's the sender, who's the server, and everything else, only then the sender will call the DATA command, in which will contain the content of the email - which consist of the email headers and body - the one that are received by email clients. Among these email headers are the usual from address, to address, CC address.
  • The BCC address is not shown to the receiver, simply because it's not printed out under the DATA command, not because the destination SMTP server stripped them away. The destination SMTP server will just refer to the RCPT TO for the list of email addresses that should receive the email content. It does not really care whether the receiver is in the To, CC or BCC list.

    Update (to clarify): BCC email addresses must be listed in the RCPT TO command list, but the BCC header should not be printed under the DATA command.

Quoting a part of the RFC that I think is relevant to your case:

Please note that the mail data includes the memo header items such as Date, Subject, To, Cc, From [2].

Rolling out your own email sender

A couple of years ago, I frankly think, is quite a long time back to assume that you still memorize end-to-end of RFC 821. :)

Issue with Cc and Bcc in sending mails using SMTP - PHP

Diagnose:

Your mail server does not strip Bcc: headers.

Fix:
Do not specify bcc recipients in BCC: headers.

Add the bcc recipients to first parameter of send.

http://pear.php.net/manual/en/package.mail.mail.send.php

SendGrid SMTP emails are not delivered to CC and BCC addresses in Go

Under the covers, smtp.SendMail calls smtp.Client.Rcpt for each to recipient.
The to slice directs who will actually receive the email. The addressees in the body of the email is purely informational - in fact they don't even need to match the real addressee info.

So to fix your addressing issue, you need to collect all to, cc & bcc addressees:

var all []string
for _, a := range [][]string{email.To, email.CC, email.BCC} {
all = append(all, a)
}

err := smtp.SendMail(
config.Config.EmailClientHost+":"+config.Config.EmailClientPort,
smtpAuth,
email.From,
all, //email.To,
emailMessageBytes,
)

also since every recipient receives the body of the e-mail, bcc users should not be listed in the
body, for obvious privacy reasons.

So remove this:

// if len(m.BCC) > 0 {
// buf.WriteString(fmt.Sprintf("Bcc: %s\r\n", strings.Join(m.BCC, ",")))
//}

python: how to send mail with TO, CC and BCC?

Email headers don't matter to the smtp server. Just add CC and BCC recipients to toaddrs when sending emails. For CC, add them to the CC header.

toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %s\r\n" % fromaddr
+ "To: %s\r\n" % toaddr
+ "CC: %s\r\n" % ",".join(cc)
+ "Subject: %s\r\n" % message_subject
+ "\r\n"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()

python emailing using BCC by default instead of To

From https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.sendmail:

Note The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. The SMTP does not modify the message headers in any way.

So this means that you construct the "To:" headers that recipients will see in the message body, but choose actual recipients the message will go to in the to_addrs parameter to sendmail. For example:

message='To: {}\r\nSubject: {}\r\n\r\n{}'.format('visible@example.com', subject, body)

smtp = smtplib.SMTP(server)
smtp.sendmail(send_from, ['visible@example.com', 'invisible@example.com'], message)
smtp.quit()

and invisible@example.com will be BCC'd.

PHP send email BCC & CC using SMTP

The carbon copy is an header.
All recipients are recipients in the same way for the mail server, the difference between carbon copy and blind carbon copy is just a matter of declaring it in the headers.

$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8',
'Cc' => $cc
);

How to send bcc email via `exim -t`? [sendmail look alike mode]

"Sendmail look alike" mode with-t removes Bcc: headers after processing them.

In -t mode Bcc: headers content will be appended to the (SMTP) recipients list BUT recipients will not see/receive Bcc: headers.

Style guide suggestion: IF you use another SMTP/MTA soft (e.g. Exim) in "sendmail look alike" (command line comparability mode) THEN use sendmail program/binary provided by them.

const sendmail = "/usr/sbin/sendmail"

Sending Mail via SMTP in C# using BCC without TO

I think if you comment out the whole emailMessage.To.Add(sendTo); line , it will send the email with To field empty.



Related Topics



Leave a reply



Submit