ReleaseResource;
The ReleaseResource method deallocates the resource that is used as an email message attachment.
Executing the example requires that the file system contains the image files: D:\image01.jpg, D:\image02.jpg.
Add links to the Forms and Net system assemblies.
Sub UserProc;
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("D:\image01.jpg");
AttachCollect := Message.Attachments;
AttachCollect.Add(Attach);
Attach := New CurlAttachment.Create("D:\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 UserProc;
After executing the example the message is sent via the specified mail server. 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.
See also: