Hi,
i am having trouble in releasing the cdo.message object when there is a error. i have a mailing subroutine with file location of the attachment to be sent as a parameter.
After sending the mail the file which was sent as attachment has to be deleted from the file system. even if the mailing sub fails i still want to delete the attachment file from the file system, hence in error handler i again included the release cdo lines. so that when the mailing sub ends the main sub can delete this file
below is the code sample.
with proper settings and working smtp the mailing sub works properly.
then in the main sub the attachment file gets deleted as well
but when i keep any invalid smtp address, the error handler is not serving the purpose of releasing CDO object. because the next instruction in main which is kill(attachment) doesnt seem to be doing anything when i step through the code.
there is just no error shown when i step through kill(attachement) line.
which means that the file is still locked some where in the cdo object.
Also earlier i had the same thing VBA excel. there it didnt give me issues with releasing cdo reference to the attachment. its only in VB.net
Thanks!!! in advance if some one can really help me through it
i am having trouble in releasing the cdo.message object when there is a error. i have a mailing subroutine with file location of the attachment to be sent as a parameter.
After sending the mail the file which was sent as attachment has to be deleted from the file system. even if the mailing sub fails i still want to delete the attachment file from the file system, hence in error handler i again included the release cdo lines. so that when the mailing sub ends the main sub can delete this file
below is the code sample.
VB.NET:
sub mainn()
Send_Email_Using_CDO(attachment) 'location of the attachment is passed
kill(attachment) - delete the original file from the filesystem
end sub
Private Sub Send_Email_Using_CDO(ByVal location As String)
On Error GoTo ErrorHandler
Dim objmessage As Object
objmessage = CreateObject("CDO.Message")
objmessage.AddAttachment(wblocation)
...
objmessage.configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
abc.gef.com ' a inactive smtp address is given to check the error handler
objmessage.send() ---> deliberate error introduced; wrong smtp address given
objmessage = nothing
ErrorHandler:
If Err.Number <> 0 Then
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
Marshal.FinalReleaseComObject(objmessage)
objmessage = Nothing
end sub
with proper settings and working smtp the mailing sub works properly.
then in the main sub the attachment file gets deleted as well
but when i keep any invalid smtp address, the error handler is not serving the purpose of releasing CDO object. because the next instruction in main which is kill(attachment) doesnt seem to be doing anything when i step through the code.
there is just no error shown when i step through kill(attachement) line.
which means that the file is still locked some where in the cdo object.
Also earlier i had the same thing VBA excel. there it didnt give me issues with releasing cdo reference to the attachment. its only in VB.net
Thanks!!! in advance if some one can really help me through it
Last edited: