ReleaseResource;
The ReleaseResource method deallocates the resource that is used as an email message attachment.
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 message";
Message.Body := "Message 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 message is sent via the specified mail server on clicking the button. Two files named image01.jpg and image02.jpg are added to the message 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: