ReleaseResource;
The ReleaseResource method deallocates the resource that is used as an attachment to email message.
Executing the example requires a form with the Button1 button.
Sub Button1OnClick(Sender: Object; Args: IEventArgs);
Var
From_, To_: INetMailAddress;
Attach: INetAttachment;
AttachCollect: INetAttachmentCollection;
Message: INetMailMessage;
Client: INetSmtpClient;
i: Integer;
Begin
From_ := New NetMailAddress.Create("ivanov@server.ru");
To_ := New NetMailAddress.Create("petrov@mail.ru");
Message := New NetMailMessage.CreateWithFromAndTo(From_, To_);
Message.Subject := "Test letter";
Message.Body := "The letter text is specified here";
Attach := New NetAttachment.Create("c:\image1.jpg");
AttachCollect := Message.Attachments;
AttachCollect.Add(Attach);
Attach := New NetAttachment.Create("c:\image2.jpg");
AttachCollect.Add(Attach);
Client := New NetSmtpClient.CreateWithHost("example.server.ru");
Client.Send(Message);
For i := 0 To AttachCollect.Count - 1 Do
AttachCollect.Item(i).ReleaseResource;
End For;
End Sub Button1OnClick;
After executing the example a letter is sent via the specified mail server on clicking the button. Two files named image01.jpg and image02.jpg are added to the letter as attachments. After the message sending, both files are released to make them available for operations in the operating system until the form work is completed.
See also: