473,714 Members | 2,598 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 4556
* 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
1848
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
3633
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
2576
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
1662
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
1997
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
4424
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
2145
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
6973
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
8707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9314
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
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...
1
9074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6634
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
5947
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
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.