2 attachment in TScMailMessage

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
ppitu
Posts: 1
Joined: Thu 23 Dec 2021 14:48

2 attachment in TScMailMessage

Post by ppitu » Thu 23 Dec 2021 14:50

Hi,

How can I send an email with more than one attachment using TScMailMessage component from SecureBridge?

YanishevskiyVI
Devart Team
Posts: 62
Joined: Wed 02 Jun 2021 09:30

Re: 2 attachment in TScMailMessage

Post by YanishevskiyVI » Fri 24 Dec 2021 13:23

Hi there!

Please be informed that there is a way to send as many attachments as you need. To do this, please perform the following:

Code: Select all

uses
  ...ScSMTPUtils, ScMailMessage...
...
  ScSMTPClient1: TScSMTPClient;
...  

procedure SendMail;
var
  MailMessage: TScMailMessage;
  Attachment: TScAttachment;
begin
  //Creating mail message
  MailMessage := TScMailMessage.Create;
  MailMessage.ToAddress.Add.AsString := 'FirstName1 SecondName1 <mailbox1@host>';//first recipient
  MailMessage.ToAddress.Add.AsString := 'FirstName2 SecondName2 <mailbox2@host>';//second recipient
  //...and so on
  MailMessage.Sender.AsString := 'SenderFirstName SenderSecondName <sendermailbox@host>';
  MailMessage.Subject := 'A sample mail with many attachments';
  MailMessage.SubjectCharset:='iso-8859-1';//affect to Subject Charset
  MailMessage.Body.LoadFromFile('MessageBody.txt');
  MailMessage.ContentType:='text/plain';
  MailMessage.ContentCharset := 'iso-8859-1';//affect to Body Charset
  //Attachments
  //first attachment
  Attachment := TScAttachment(MailMessage.Attachments.Add);
  Attachment.LoadFromFile('Attachment.pdf');
  Attachment.ContentType := 'application/pdf';
  //second attachment
  Attachment := TScAttachment(MailMessage.Attachments.Add);
  Attachment.LoadFromFile('Attachment.jpg');
  Attachment.ContentType := 'image/jpeg';
  //...and so on
  //connection info
  ScSMTPClient1.Uri := '...';
  ScSMTPClient1.Port := XXX;
  ScSMTPClient1.Username := '...';
  ScSMTPClient1.Password := '...';
  //sending mail
  try
    ScSMTPClient1.Connect;
    ScSMTPClient1.Authenticate;
    ScSMTPClient1.Send(MailMessage);
    ScSMTPClient1.Disconnect;
  finally
    MailMessage.Free;
  end;
end;

Post Reply