473,388 Members | 976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Error when trying to send email from Windows Service

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(Obje ct obj, String
propName, Object propKey, Object propValue)
--- End of inner exception stack trace ---
at System.Web.Mail.LateBoundAccessHelper.SetProp(Obje ct 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
Nov 20 '05 #1
3 4528
* ge*****@networkpro.co.nz (Gerard) scripsit:
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.


Did you already have a look at <URL:http://www.systemwebmail.net/>?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in message news:<2g************@uni-berlin.de>...
* ge*****@networkpro.co.nz (Gerard) scripsit:
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.


Did you already have a look at <URL:http://www.systemwebmail.net/>?


Yes I have looked and looked again.

I can take the exact same code, create a windows application and it
works. However anything I try within a windows service produces the
error. I am sure it is possible to send email from within windows
services, I just can't for the life of me work out how nor can I find
anything on google to help...

The heart of the error seems to be: "System.IO.FileNotFoundException:
The specified module could not be found." I would think this is
system.web.dll however it exists and as said, sending email using it
within a windows app works. I don't know much about services but would
imagine that all the links etc work the same whether you use a service
or an app in the .net framework.

Again, any help appreciated...
Nov 20 '05 #3
Solution found

I didn't know enough about services, i.e. that you have to
specifically create a thread to do the work. You can't use the onstart
method.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brett | last post by:
I am currently in the process of building a vb.net windows application that will be used to send faxes and monitor these faxes as they are sent. In the project I am building the fax functionality...
2
by: Mark Sanders | last post by:
Configuration: - ASP.NET web service running on a Windows 2000 server. - Exchange server running on a Windows 2000 server. - The web server and the exchange server are on different computers in...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
4
by: MadeOfRose | last post by:
Hi all i was using cdo object for sending email to a customers. when use win2000 server or windows xp my script works correctly. but not on win2003 server r2. Different thing on my script is...
16
by: Ed Bitzer | last post by:
Trying to send groups of email with program using System.Net.Mail. I do not clear MailMessage but repeatedly loop changing only the Bcc entries. Works fine if all addresses are valid. As a simple...
6
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
Hi - I have 4 webservers in my webfarm. All Win2k3 web edition. Before yesterday, none of them were service packed. I have now applied SP2 to two of them, and I'm getting a very weird MSDTC...
3
by: Lance Wynn | last post by:
Hello, I am receiving this error when trying to instantiate a webservice component. I have 2 development machines, both are XP sp2 with VS 2008 installed. On one machine, the code works fine. On...
8
by: Frank Hauptlorenz | last post by:
Hello out there, I changed an existing and good working webservice from an wsHttpBinding to an NetTcpBinding. This is working (after trying some time) and has real a better performance! But...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.