NetAttachment.Create

Syntax

Create(FileName: String);

Parameters

FileName. Path and name of the file, which must be used as attachment to email message.

Description

The Create constructor creates the object that is an attachment to email message.

Example

To execute the example, add a link to the Net system assembly. The Image01.jpeg file is required in the disk C root directory.

Sub UserProc;
Var
    From_, To_: INetMailAddress;
    Message: INetMailMessage;
    Attach: INetAttachment;
    Client: INetSmtpClient;
    Credent: NetNetworkCredential;
Begin
    From_ := New NetMailAddress.Create("user1@example.ru");
    To_ := New NetMailAddress.Create("user2@example.ru");
    Message := New NetMailMessage.CreateWithFromAndTo(From_, To_);
    Message.Subject := "Test message";
    Message.Body := "Message text";
    Attach := New NetAttachment.Create("c:\Image01.jpg");
    Message.Attachments.Add(Attach);
    Client := New NetSmtpClient.CreateWithHost("example.server.ru");
    Credent := New NetNetworkCredential.Create("user1""password""domain");
    Client.ThisHostCredentials("https") := Credent;
    Client.Send(Message);
End Sub UserProc;

After executing the example an email message with the topic "Test message" and the text "Message text" is sent from the mail address user1@example.ru to the mail address user2@example.ru. The Image01.jpeg file is attached to the message. The message is sent via the example.server.ru mail server working on HTTPS protocol. The credentials of the user1 user are used to authorize at the mail server.

See also:

NetAttachment