473,836 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ht tpException: Could not access 'CDO.Message'
object. ---> System.Reflecti on.TargetInvoca tionException: Exception
has been thrown by the target of an invocation. --->
System.IO.FileN otFoundExceptio n: The specified module could not be
found.

--- End of inner exception stack trace ---
at System.RuntimeT ype.InvokeDispM ethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters )
at System.RuntimeT ype.InvokeMembe r(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifi er[] modifiers, CultureInfo culture, String[]
namedParameters )
at System.Type.Inv okeMember(Strin g name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args)
at System.Web.Mail .LateBoundAcces sHelper.SetProp (Type type, Object
obj, String propName, Object propKey, Object propValue)
at System.Web.Mail .LateBoundAcces sHelper.SetProp (Object obj, String
propName, Object propKey, Object propValue)
--- End of inner exception stack trace ---
at System.Web.Mail .LateBoundAcces sHelper.SetProp (Object obj, String
propName, Object propKey, Object propValue)
at System.Web.Mail .CdoSysHelper.S etField(Object m, String name,
String value)
at System.Web.Mail .CdoSysHelper.S end(MailMessage message)
at System.Web.Mail .SmtpMail.Send( MailMessage message)
at SGMSTrafficMoni torService.Emai l.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("Se nd 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.SM TPServerAddress

' 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.Em ailFrom

' specify the body format...
msgMail.BodyFor mat = MailFormat.Html

' add a reply to header...
msgMail.Headers .Add("Reply-To", _appSettings.Em ailReplyTo)

' mail subject...
msgMail.Subject = subject

' mail body...
msgMail.Body = body

Try
' call the send method to send the mail...
obj.Send(msgMai l)

return True

Catch ex As Exception

Dim errMessage As String
errMessage = "Unable to send email, error details: " _
& "Index #:" & ex.ToString() &
ControlChars.Ne wLine _
& "Message: " & ex.Message &
ControlChars.Ne wLine _
& "Inner Exception: " &
ex.InnerExcepti on.Message _
& ControlChars.Ne wLine _
& "Source: " & ex.Source & ControlChars.Ne wLine

' log error...
_eventlog.Write ToEventLog(errM essage,
EventLogEntryTy pe.Error)

' return failure...
return False

End Try

End Function

Sorry for the long post... Any help appreciated.

Cheers
Gerard
Nov 20 '05 #1
3 4562
* ge*****@network pro.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.Ht tpException: Could not access 'CDO.Message'
object. ---> System.Reflecti on.TargetInvoca tionException: Exception
has been thrown by the target of an invocation. --->
System.IO.FileN otFoundExceptio n: The specified module could not be
found.


Did you already have a look at <URL:http://www.systemwebma il.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*****@network pro.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.Ht tpException: Could not access 'CDO.Message'
object. ---> System.Reflecti on.TargetInvoca tionException: Exception
has been thrown by the target of an invocation. --->
System.IO.FileN otFoundExceptio n: The specified module could not be
found.


Did you already have a look at <URL:http://www.systemwebma il.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.File NotFoundExcepti on:
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
1411
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 into a single web form in order to encapsulate this functionality. The error I am receiving has brought me to the point of starting a brand new project with just the web-form for faxing. I am using code provided by Microsoft:...
2
1850
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 the network. Problem: Whenever I try to send an email, via my ASP.NET web service, using the SmtpMail object I receive the following HttpException message: "Could not access 'CDO.Message' object." Now, the interesting thing is that this will
5
3654
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 New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
4
2580
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 i use external smtp server to send my emails. for example, i dont use the iis' virtual smtp server. i assign an another smtp server
16
1677
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 test I have attempted to send a valid address, then an invalid address which my ISP (Comcast) will reject immediately as "Not our customer". I catch the exception, display and then continue looping to send several additional valid. The balance...
6
2012
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 error on them now. The error occurs when I attempt a series of SQL statements wrapped in a TransactionScope(). It's executing against a different server, so this is where it's elevated to a distributed transaction.
3
4433
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 the other machine I get the error upon instantiating the service client. I add the reference by choosing Add Service Reference from the project menu, and pointing to the remote wsdl file. I can't seem to find what the difference between the two...
8
2150
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 one thing is strange: when I'm now actualising the web reference from within VS2008, VS2008 creates a 2nd endpoint config in my app.conf. The endpoint is exactly the same as the existing but the name and
10
6987
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 of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10556
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9383
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6980
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.