Recent

Author Topic: Synapse BCC  (Read 466 times)

cappe

  • Full Member
  • ***
  • Posts: 191
Synapse BCC
« on: March 31, 2023, 02:52:05 pm »
Hi, I found a solution that seems to work for BCC with synapse.

    EncodeMessage; // after this procedure
    Header.ToList.Add(Bcc); // here I put the Bcc

and it seems to work

paweld

  • Hero Member
  • *****
  • Posts: 991
Re: Synapse BCC
« Reply #1 on: March 31, 2023, 03:17:46 pm »
if you do it this way, the recipients will see the BCC address on the list. 
I send it this way:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   sl_text, sl_html: TStringList;
  4.   MimeMsg: TMimeMess;
  5.   SMTPSend: TSMTPSend;
  6.   MIMEPart, MIMEPart2, HTMLPart: TMimePart;
  7.   i: Integer;
  8. begin
  9.   sl_text := TStringList.Create;
  10.   sl_text.Text := 'Hello world';
  11.   sl_html := TStringList.Create;
  12.   sl_html.Text := '<html><body><font size=7><b>Hello</b></font> <i>world</i><br />Zażółć gęślą jaźń</body></html>';
  13.   MimeMsg := TMimeMess.Create;
  14.   SMTPSend := TSMTPSend.Create;
  15.   try
  16.     MimeMsg.Header.From := 'Test <test@example.com>';
  17.     MimeMsg.Header.ToList.Add('user1@another-domain.com');
  18.     MimeMsg.Header.ToList.Add('user2@another-domain.com');
  19.     MimeMsg.Header.CCList.Add('copy@another-domain.com');
  20.     MimeMsg.Header.Subject := 'Test message';
  21.     MimeMsg.Header.Priority := MP_high;
  22.     MimeMsg.Header.CustomHeaders.Add('Disposition-Notification-To: ' + MimeMsg.Header.From); //read confirmation
  23.     MimeMsg.Header.Date := Now;
  24.     MimeMsg.Header.XMailer := 'lazarus';
  25.     MimeMsg.Header.CharsetCode := UTF_8;
  26.     MimeMsg.Header.ReplyTo := 'Test <test@example.com>';
  27.     MIMEPart := MimeMsg.AddPartMultipart('related', nil);
  28.     MIMEPart.CharsetCode := UTF_8;
  29.     HTMLPart := MimeMsg.AddPart(MIMEPart);
  30.     HTMLPart.ConvertCharset := False;
  31.     with HTMLPart do
  32.     begin
  33.       sl_html.SaveToStream(DecodedLines);
  34.       Primary := 'text';
  35.       Secondary := 'html';
  36.       Description := 'HTML text';
  37.       Disposition := 'inline';
  38.       CharsetCode := UTF_8;
  39.       EncodingCode := ME_QUOTED_PRINTABLE;
  40.       EncodePart;
  41.       EncodePartHeader;
  42.     end;
  43.     MIMEPart2 := MimeMsg.AddPartMultipart('alternative', MIMEPart);
  44.     MIMEPart2.CharsetCode := UTF_8;
  45.     MimeMsg.AddPartTextEx(sl_text, MIMEPart2, UTF_8, True, ME_8BIT); //add alternative text message
  46.     MimeMsg.EncodeMessage;
  47.     SMTPSend.TargetHost := 'smtp.example.com';
  48.     SMTPSend.TargetPort := '587';
  49.     SMTPSend.UserName := 'test@example.com';
  50.     SMTPSend.Password := 'myemailpassword';
  51.     SMTPSend.AutoTLS := False;
  52.     SMTPSend.FullSSL := False;
  53.     if SMTPSend.Login then
  54.     begin
  55.       if SMTPSend.AuthDone then
  56.       begin
  57.         SMTPSend.MailFrom(email, Length(MimeMsg.Lines.Text));
  58.         for i := 0 to MimeMsg.Header.ToList.Count - 1 do  //TO
  59.           SMTPSend.MailTo(MimeMsg.Header.ToList[i]);
  60.         for i := 0 to MimeMsg.Header.CCList.Count - 1 do  //CC
  61.           SMTPSend.MailTo(MimeMsg.Header.CCList[i]);
  62.         SMTPSend.MailTo('admin@example.com');  //BCC
  63.         if SMTPSend.MailData(MimeMSg.Lines) then
  64.         begin
  65.           SMTPSend.Logout;
  66.           Caption := 'ok';
  67.         end
  68.         else
  69.           Caption := 'message error: ' + SMTPSend.ResultString;
  70.       end
  71.       else
  72.         Caption := 'auth error: ' + SMTPSend.ResultString;
  73.     end
  74.     else
  75.       Caption := 'login error: ' + SMTPSend.ResultString;
  76.   finally
  77.     FreeAndNil(MimeMsg);
  78.     FreeAndNil(SMTPSend);
  79.   end;
  80.   sl_text.Free;
  81.   sl_html.Free;
  82. end;
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 14362
  • Sensorship about opinions does not belong here.
Re: Synapse BCC
« Reply #2 on: March 31, 2023, 04:32:04 pm »
and it seems to work
Never, ever, take shortcuts like that. BCC is meant to be a private, one way, notification.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018