473,320 Members | 1,978 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,320 software developers and data experts.

sending Mail in a Service

Hi,

I need to send some emails in my Windows Service (VB.NET 2005). I made for
that a simple class, which works fine when I use it in a Windows Forms
application.

Although: When I put it in my Windows Service I got problems:
- I'm not able to let the Service send e-mails.
- When I let my service send an e-mail during the Starting or Stoping of the
Service, it takes minutes before the Service is started or stopped (and no
e-mail is send).

Is there any particular reason for this? Can't Services send emails, or what
am I possibly doing wrong?

Any help would be really appreciated!

thanks a lot in advance,

Pieter

The class I use for sending the mails is this:
Option Explicit On

Public Class clsMail

Public Sub SendMail(ByVal strTo As String, ByVal strSubject As String,
ByVal strMessage As String)
Dim Appl As Object
Dim out As Object
Try
Appl = CreateObject("Outlook.Application")
out = Appl.CreateItem(0)
With out
.Subject = strSubject
.To = strTo
.Body = strMessage

'Send it!
.Send()
End With
Catch ex As Exception
ErrorMessageSilent(Me, ex)
End Try
End Sub

End Class
Jul 21 '05 #1
3 1394
You might try using the System.Web.Mail namespace instead of Outlook.
You'll have to add a reference to System.Web.dll to access the namespace.
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Hi,

I need to send some emails in my Windows Service (VB.NET 2005). I made for
that a simple class, which works fine when I use it in a Windows Forms
application.

Although: When I put it in my Windows Service I got problems:
- I'm not able to let the Service send e-mails.
- When I let my service send an e-mail during the Starting or Stoping of
the
Service, it takes minutes before the Service is started or stopped (and no
e-mail is send).

Is there any particular reason for this? Can't Services send emails, or
what
am I possibly doing wrong?

Any help would be really appreciated!

thanks a lot in advance,

Pieter

The class I use for sending the mails is this:
Option Explicit On

Public Class clsMail

Public Sub SendMail(ByVal strTo As String, ByVal strSubject As String,
ByVal strMessage As String)
Dim Appl As Object
Dim out As Object
Try
Appl = CreateObject("Outlook.Application")
out = Appl.CreateItem(0)
With out
.Subject = strSubject
.To = strTo
.Body = strMessage

'Send it!
.Send()
End With
Catch ex As Exception
ErrorMessageSilent(Me, ex)
End Try
End Sub

End Class

Jul 21 '05 #2
I tried using the System.Web.Mail and added a reference to System.Web.dll but
it's not recognizing MailMessage or SmtpMail.

"Terry Olsen" wrote:
You might try using the System.Web.Mail namespace instead of Outlook.
You'll have to add a reference to System.Web.dll to access the namespace.
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Hi,

I need to send some emails in my Windows Service (VB.NET 2005). I made for
that a simple class, which works fine when I use it in a Windows Forms
application.

Although: When I put it in my Windows Service I got problems:
- I'm not able to let the Service send e-mails.
- When I let my service send an e-mail during the Starting or Stoping of
the
Service, it takes minutes before the Service is started or stopped (and no
e-mail is send).

Is there any particular reason for this? Can't Services send emails, or
what
am I possibly doing wrong?

Any help would be really appreciated!

thanks a lot in advance,

Pieter

The class I use for sending the mails is this:
Option Explicit On

Public Class clsMail

Public Sub SendMail(ByVal strTo As String, ByVal strSubject As String,
ByVal strMessage As String)
Dim Appl As Object
Dim out As Object
Try
Appl = CreateObject("Outlook.Application")
out = Appl.CreateItem(0)
With out
.Subject = strSubject
.To = strTo
.Body = strMessage

'Send it!
.Send()
End With
Catch ex As Exception
ErrorMessageSilent(Me, ex)
End Try
End Sub

End Class


Jul 21 '05 #3
Hi,

System.Web.Mail worked indeed fine for me! Thanks Terry!!

This is my class rroman:

Option Explicit On

Imports System.Web.Mail

Public Class clsMail
'These values are needed!!
Private pryFrom As String 'My Adress
Private prySmtpServer As String 'My SmtpServer

Public Sub New(ByVal strFrom As String, ByVal strSmtpServer As String)
pryFrom = strFrom
prySmtpServer = strSmtpServer
End Sub

Public Sub SendMail2(ByVal strTo As String, ByVal strSubject As String,
ByVal strMessage As String)
Dim oMail As New MailMessage

Try
With oMail
.From = pryFrom
.Subject = strSubject
.To = strTo
.Body = strMessage
End With
SmtpMail.SmtpServer = prySmtpServer

'send it:
SmtpMail.Send(oMail)
Catch ex As Exception
ErrorMessageSilent(Me, ex)
End Try
End Sub


"rr****@800mcmahan.com" <rr*****************@discussions.microsoft.com>
wrote in message news:03**********************************@microsof t.com...
I tried using the System.Web.Mail and added a reference to System.Web.dll but it's not recognizing MailMessage or SmtpMail.

"Terry Olsen" wrote:
You might try using the System.Web.Mail namespace instead of Outlook.
You'll have to add a reference to System.Web.dll to access the namespace.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl...
Hi,

I need to send some emails in my Windows Service (VB.NET 2005). I made for that a simple class, which works fine when I use it in a Windows Forms
application.

Although: When I put it in my Windows Service I got problems:
- I'm not able to let the Service send e-mails.
- When I let my service send an e-mail during the Starting or Stoping of the
Service, it takes minutes before the Service is started or stopped (and no e-mail is send).

Is there any particular reason for this? Can't Services send emails, or what
am I possibly doing wrong?

Any help would be really appreciated!

thanks a lot in advance,

Pieter

The class I use for sending the mails is this:
Option Explicit On

Public Class clsMail

Public Sub SendMail(ByVal strTo As String, ByVal strSubject As String, ByVal strMessage As String)
Dim Appl As Object
Dim out As Object
Try
Appl = CreateObject("Outlook.Application")
out = Appl.CreateItem(0)
With out
.Subject = strSubject
.To = strTo
.Body = strMessage

'Send it!
.Send()
End With
Catch ex As Exception
ErrorMessageSilent(Me, ex)
End Try
End Sub

End Class


Jul 21 '05 #4

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

Similar topics

6
by: Owen | last post by:
I am sending email using CDO but it only seems to work when the "To" address is within the same domain as mine. When I send to an outside domain (eg. yahoo.com) the mail simply does not reach...
3
by: Jason E. Trout | last post by:
I created at VB.NET application that sends e-mail via the System.Web.Mail namespace. At the application level, the e-mails send out fine. When I created the application as a Windows service, the...
3
by: DraguVaso | last post by:
Hi, I need to send some emails in my Windows Service (VB.NET 2005). I made for that a simple class, which works fine when I use it in a Windows Forms application. Although: When I put it in...
3
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
8
by: Mike Owen | last post by:
Hi, I am using the following code to send email on a Windows 2003 Web Server: Imports System.Net.Mail ........ Dim msgmail As New MailMessage msgmail.To.Add(New...
3
by: Ibrahim. | last post by:
Hello, Im getting the following error when mail is sent from ASP.NET 2.0 website. CDO.Messaging componenet is used for sending mail. " The message was not able to be transmitted to the SMTP...
8
by: Robert Dufour | last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com", "Test", "Test") Dim emailClient As New SmtpClient("localhost") emailClient.Send(message) The IIS server is...
1
rsrinivasan
by: rsrinivasan | last post by:
Hi, I am Sending mail from java. When I run the program I hava Following error.. DEBUG: setDebug: JavaMail version 1.4ea DEBUG: getProvider() returning javax.mail.Provider DEBUG SMTP:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.