Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / November 2004

Tip: Looking for answers? Try searching our database.

sending Mail in a Service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DraguVaso - 04 Nov 2004 10:36 GMT
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
Terry Olsen - 04 Nov 2004 14:56 GMT
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.

> Hi,
>
[quoted text clipped - 46 lines]
>
> End Class
rroman@800mcmahan.com - 04 Nov 2004 19:29 GMT
I tried using the System.Web.Mail and added a reference to System.Web.dll but
it's not recognizing MailMessage or SmtpMail.  

> 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.
[quoted text clipped - 49 lines]
> >
> > End Class
DraguVaso - 05 Nov 2004 12:40 GMT
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

> I tried using the System.Web.Mail and added a reference to System.Web.dll but
> it's not recognizing MailMessage or SmtpMail.
[quoted text clipped - 52 lines]
> > >
> > > End Class

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.