ReleaseResource;
The ReleaseResource method deallocates the resource that is used as an email message attachment.
Executing the example requires a form containing the Button component named Button1. The file system should also include the image files: С:\image01.jpg and С:\image02.jpg.
Add links to the Forms and Net system assemblies.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
From_, To_: INetMailAddress;
Attach: INetAttachment;
AttachCollect: INetAttachmentCollection;
Message: INetMailMessage;
Client: INetSmtpClient;
i: Integer;
Begin
From_ := New CurlMailAddress.Create("ivanov@server.ru");
To_ := New CurlMailAddress.Create("petrov@mail.ru");
Message := New CurlMailMessage.CreateWithFromAndTo(From_, To_);
Message.Subject := "Test message";
Message.Body := "Message text is placed here";
Attach := New CurlAttachment.Create("c:\image01.jpg");
AttachCollect := Message.Attachments;
AttachCollect.Add(Attach);
Attach := New CurlAttachment.Create("c:\image02.jpg");
AttachCollect.Add(Attach);
Client := New CurlSmtpClient.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 this 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: