G
Gerard
Hello
I have created a windows service to monitor a database, it starts some
checks when a timer elapses. The checks send emails depending on their
findings. My issue is that when I created a windows application it
worked fine, however I need to use a service as I don't want to rely
on a user being logged in. The errors I get are:
Index #:System.Web.HttpException: Could not access 'CDO.Message'
object. ---> System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.IO.FileNotFoundException: The specified module could not be
found.
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args)
at System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object
obj, String propName, Object propKey, Object propValue)
at System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propKey, Object propValue)
--- End of inner exception stack trace ---
at System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propKey, Object propValue)
at System.Web.Mail.CdoSysHelper.SetField(Object m, String name,
String value)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at SGMSTrafficMonitorService.Email.Send(String toAddress, String
subject, String body, String CCAddress, String BCCAddress) in
C:\_Development\Classes\Email.vb:line 79
Message: Could not access 'CDO.Message' object.
Inner Exception: Exception has been thrown by the target of an
invocation.
Source: System.Web
I have included System.Web.dll however it seems to be something else.
The code which sends the email is in its own class:
Public Function Send(ByVal toAddress As String, _
ByVal subject As String, _
ByVal body As String, _
Optional ByVal CCAddress As String = "", _
Optional ByVal BCCAddress As String = "") As
Boolean
Debug.Write("Send started")
' initialise return value...
Send = False
' variable which will send the mail...
Dim obj As System.Web.Mail.SmtpMail
' variable to create the message to send...
Dim msgMail As MailMessage = New MailMessage
' set the properties
' assign the SMTP server...
obj.SmtpServer = _appSettings.SMTPServerAddress
' address of the recipient(s)...
If Len(toAddress) > 0 Then msgMail.To = toAddress
If Len(CCAddress) > 0 Then msgMail.Cc = CCAddress
If Len(BCCAddress) > 0 Then msgMail.Bcc = BCCAddress
' the from address...
msgMail.From = _appSettings.EmailFrom
' specify the body format...
msgMail.BodyFormat = MailFormat.Html
' add a reply to header...
msgMail.Headers.Add("Reply-To", _appSettings.EmailReplyTo)
' mail subject...
msgMail.Subject = subject
' mail body...
msgMail.Body = body
Try
' call the send method to send the mail...
obj.Send(msgMail)
return True
Catch ex As Exception
Dim errMessage As String
errMessage = "Unable to send email, error details: " _
& "Index #:" & ex.ToString() &
ControlChars.NewLine _
& "Message: " & ex.Message &
ControlChars.NewLine _
& "Inner Exception: " &
ex.InnerException.Message _
& ControlChars.NewLine _
& "Source: " & ex.Source & ControlChars.NewLine
' log error...
_eventlog.WriteToEventLog(errMessage,
EventLogEntryType.Error)
' return failure...
return False
End Try
End Function
Sorry for the long post... Any help appreciated.
Cheers
Gerard
I have created a windows service to monitor a database, it starts some
checks when a timer elapses. The checks send emails depending on their
findings. My issue is that when I created a windows application it
worked fine, however I need to use a service as I don't want to rely
on a user being logged in. The errors I get are:
Index #:System.Web.HttpException: Could not access 'CDO.Message'
object. ---> System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.IO.FileNotFoundException: The specified module could not be
found.
--- End of inner exception stack trace ---
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args)
at System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object
obj, String propName, Object propKey, Object propValue)
at System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propKey, Object propValue)
--- End of inner exception stack trace ---
at System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String
propName, Object propKey, Object propValue)
at System.Web.Mail.CdoSysHelper.SetField(Object m, String name,
String value)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at SGMSTrafficMonitorService.Email.Send(String toAddress, String
subject, String body, String CCAddress, String BCCAddress) in
C:\_Development\Classes\Email.vb:line 79
Message: Could not access 'CDO.Message' object.
Inner Exception: Exception has been thrown by the target of an
invocation.
Source: System.Web
I have included System.Web.dll however it seems to be something else.
The code which sends the email is in its own class:
Public Function Send(ByVal toAddress As String, _
ByVal subject As String, _
ByVal body As String, _
Optional ByVal CCAddress As String = "", _
Optional ByVal BCCAddress As String = "") As
Boolean
Debug.Write("Send started")
' initialise return value...
Send = False
' variable which will send the mail...
Dim obj As System.Web.Mail.SmtpMail
' variable to create the message to send...
Dim msgMail As MailMessage = New MailMessage
' set the properties
' assign the SMTP server...
obj.SmtpServer = _appSettings.SMTPServerAddress
' address of the recipient(s)...
If Len(toAddress) > 0 Then msgMail.To = toAddress
If Len(CCAddress) > 0 Then msgMail.Cc = CCAddress
If Len(BCCAddress) > 0 Then msgMail.Bcc = BCCAddress
' the from address...
msgMail.From = _appSettings.EmailFrom
' specify the body format...
msgMail.BodyFormat = MailFormat.Html
' add a reply to header...
msgMail.Headers.Add("Reply-To", _appSettings.EmailReplyTo)
' mail subject...
msgMail.Subject = subject
' mail body...
msgMail.Body = body
Try
' call the send method to send the mail...
obj.Send(msgMail)
return True
Catch ex As Exception
Dim errMessage As String
errMessage = "Unable to send email, error details: " _
& "Index #:" & ex.ToString() &
ControlChars.NewLine _
& "Message: " & ex.Message &
ControlChars.NewLine _
& "Inner Exception: " &
ex.InnerException.Message _
& ControlChars.NewLine _
& "Source: " & ex.Source & ControlChars.NewLine
' log error...
_eventlog.WriteToEventLog(errMessage,
EventLogEntryType.Error)
' return failure...
return False
End Try
End Function
Sorry for the long post... Any help appreciated.
Cheers
Gerard