Synapse smtpsend and blind copies lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ProgEd · 2013-07-21 18:03 I'm developing an application that needs to send email to a rather sizable list of people, but they all need to be blind copies (BCC). I've read the "How To" on the synapse web site, but still don't understand how to send a blind copy. Can anyone provide a piece of example code that demonstrates how to do this? Thanks, Ed ---------------------------------------------------------------------- ludob · 2013-07-22 04:17 http://synapse.ararat.cz/doku.php/public:howto:sendingbcc So you take the procedure in http://synapse.ararat.cz/doku.php/public:howto:smtpsend and drop the line Code: [Select]   msg_lines.Insert(1, 'To: ' + sTo); If you are not interested in TLS then drop the StartTLS. You should remember that in SMTP, the DATA part is not relevant. Only email clients interprete the From:, To:, Cc:,  Bcc headers. SMTP doesn't care at all. Instead of dropping the To: header it is better to replace it with a nice name such as 'VIP list' or whatever. Mails without a To: are displayed in some email clients with "To undisclosed recipients" or equivalent whcih is a good recipe to get immediately in the spam box. By the way, mails where the recipient is not in the To: or Cc: header are also being blocked more and more by spam filters. So Bcc is on its way out, as it should be. ---------------------------------------------------------------------- ProgEd · 2013-07-22 10:31 Thank you for your prompt reply. I was aware of problems with not having a recipient in the To: field, and the application will always have one (the request originator). The problem is that either it sends multiple emails to the recipients or we use BCC: since the recipients are competitors and we don't want them knowing who else is on the list of competitors. Ed ---------------------------------------------------------------------- ProgEd · 2013-08-06 00:17 Okay, I'm getting very frustrated. I've tried to do what has been specified, but it doesn't seem to be working. The BCC field is appearing in the source of the message (doing a view source), but nothing is being sent to them. Here's the code I'm using: Code: [Select]      try          sMsg.Add(Msg);          sMsg.Insert(0, 'Subject: ' + Subject);          sMsg.Insert(1, 'From: ' + sEMCont);          sMsg.Insert(2, 'To: ' + MailTo);          sMsg.Insert(3, 'Bcc: ' + Vendors);          sMsg.Insert(4,CRLF);          smtp.UserName := sEMUID;          smtp.Password := sEMPWD;          smtp.TargetHost := sEMSrvr;          smtp.TargetPort := '25';          smtp.Login();          smtp.MailFrom(sEMCont, Length(sEMCont));          smtp.MailTo(MailTo);          smtp.MailData(sMsg);          smtp.Logout();       finally          sMsg.Free;          smtp.Free;       end; Any idea what I'm doing wrong? Thanks, Ed ---------------------------------------------------------------------- ludob · 2013-08-06 04:48 I can't but repeat myself: Quote from: ludob on July 22, 2013, 06:17:13 amYou should remember that in SMTP, the DATA part is not relevant. Only email clients interprete the From:, To:, Cc:,  Bcc headers. SMTP doesn't care at all. What you have done here is just adding the Bcc to the header so that it is indeed visible for everybody that looks at the source. What you haven't done is instruct smtpsend to send it to the bcc recipients. So: - drop that Bcc line - replace the line Code: [Select]smtp.MailTo(MailTo); with a loop where you execute that line for every recipient. That is every recipient listed in To, Cc and those you want to Bcc. Only one recipient is allowed per MailTo. See http://tools.ietf.org/html/rfc5321#section-4.1.1.3 for the relevant part of the SMTP spec. If you have more than 100 recipients you should split the recipients and send the message several times. ie repeat your whole procedure with the same message but for different sets of recipients. See http://tools.ietf.org/html/rfc5321#section-4.5.3.1.10 for the error message you are getting when you exceed the number of permittted recipients. EDIT: what you are confusing is the tranfer protocol (SMTP) and the content that is transfered. The content is for the email client and goes into smtp.MailData. SMTP is the protocol that delivers the mail. It is comparable to HTTP (transfer)  and HTML (contents). Both are completely unrelated.  Bcc is a mail client concept and doesn't exist for SMTP. SMTP only transfers to a recipient specified in RCPT. If you don't want a recipient to be visible, you just don't put it in the message. SMTP doesn't care what goes in your message. Put a 'To:  Roger.Rabbit@acme.com' in your message and set RCPT to 'Daffy.Duck@acme.com', only Daffy Duck will receive the message.  Note that this is purely from a protocol perspective. The spam filters on the receivers end will look at the message content, compare RCPT to what is in the To:, Cc: sometimes Bcc: headers, etc, to decide if they deliver or not. But that has nothing to do with the SMTP protocol. ---------------------------------------------------------------------- ProgEd · 2013-08-06 14:18 Thank you. What you suggested is precisely what I had planned to do if there was no solution to my perceived problem. That, of course, does work.  Only the original "To:" address shows up in the headers, none of the other addresses appear, and yet the mail gets to them correctly. I am in your debt! Ed ---------------------------------------------------------------------- Gys · 2013-08-28 21:28 My eye fell accidentally on this thread. A bit late, but still you might find my post useful: http://forum.lazarus.freepascal.org/index.php/topic,21900.0.html