473,378 Members | 1,500 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,378 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 1397
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:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...

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.