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 / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Windows service and outlook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AMP - 01 Jul 2007 12:46 GMT
I am trying to write a windows sevice that will send emails. The data
is stored in a database and the service scans the database for new
entries

It work well as a stardard windows app, but when you make is a service
it all works except it will not sent the emails

Attached is the public sub that should run, its the same code that in
the stardard winform, both app's are using Threads

Can anyone tell me whats wroung

Many thanks

Code VB.net 2005 with Outlook 2003

Public Sub mail2()

'Redemption is a separate package that needs to be install on any
machine running this program

Dim oApp As Outlook._Application = New Outlook.Application()

Dim oNS As Outlook._NameSpace = oApp.GetNamespace("mapi")

Dim oSyncs As Outlook.SyncObjects

Dim oSync As Outlook.SyncObject

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("All Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("Redemption.SafeMailItem")

oMsg.item = oApp.CreateItem(0)

oMsg.Subject = pvsubject

oMsg.Body = pvmessage & vbCr & vbCr

oMsg.To = pvsendto

' ' Add an attachment

Dim sSource As String = pvattachment

If pvattachment <> "" Then

Dim oAttachs As Outlook.Attachments = oMsg.Attachments

Dim oAttach As Outlook.Attachment

oAttach = oAttachs.Add(sSource)

End If

' ' Send

oMsg.Send()

oSync.Start()

Catch ex As Exception

' Console.WriteLine(ex.Message)

' Me.EventLog.WriteEntry(ex.Message)

End Try

End sub
Jay B. Harlow [MVP - Outlook] - 01 Jul 2007 15:03 GMT
AMP,
> I am trying to write a windows sevice that will send emails. The data
> is stored in a database and the service scans the database for new
> entries

> Dim oApp As Outlook._Application = New Outlook.Application()

> Can anyone tell me whats wroung

Simple.

Outlook.Application is not allowed (not supported, doesn't work) in a
service. Period.

> oMsg = CreateObject("Redemption.SafeMailItem")
I would suggest you either use just Redemption to send the message.

However a .NET application (such as Windows Service & ASP.NET) that simply
want to send an email I would suggest using System.Net.Mail.
http://www.systemnetmail.com/

Signature

Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net

> I am trying to write a windows sevice that will send emails. The data
> is stored in a database and the service scans the database for new
[quoted text clipped - 76 lines]
>
> End sub
Michel Posseth  [MCP] - 01 Jul 2007 20:05 GMT
use the mail class , much easier and works from a service , web app ,
desktop app

You only need the values of a SMTP capable mail server in your network , in
the case of an exchange server you must allow SMTP trafic and thus connect
through SMTP to the server instead of mapi .

regards

Michel

> I am trying to write a windows sevice that will send emails. The data
> is stored in a database and the service scans the database for new
[quoted text clipped - 76 lines]
>
> End sub
Cor Ligthert [MVP] - 02 Jul 2007 05:59 GMT
Michel,

AFAIK you can get it in that way in your Exchange Server in a special map,
and I assume that that is the purpose.

Cor

"Michel Posseth [MCP]" <MSDN@posseth.com> schreef in bericht
news:e491MJBvHHA.2008@TK2MSFTNGP03.phx.gbl...

> use the mail class , much easier and works from a service , web app ,
> desktop app
[quoted text clipped - 87 lines]
>>
>> End sub
Michel Posseth  [MCP] - 02 Jul 2007 06:16 GMT
well i mention exchange explicitly cause i had some problems myself with it
some time ago

at the previous company  i worked there was a Linux SMTP server wich worked
fine , in my new company we have exchange installed wich did not work with
the system.net.mail  until someone in the groups told me that SMTP should be
activated on the exchange server in my case it wasn`t , and a quick talk to
the tech guy resolved my problem   :-)

But it caused me a lot of frustration that i couldn`t get it to work in the
first case

"Michel Posseth [MCP]" <MSDN@posseth.com> schreef in bericht
news:e491MJBvHHA.2008@TK2MSFTNGP03.phx.gbl...

> use the mail class , much easier and works from a service , web app ,
> desktop app
[quoted text clipped - 87 lines]
>>
>> End sub
Cor Ligthert [MVP] - 02 Jul 2007 18:20 GMT
I was meaning the mail, in a map, not the process itself, that you can find
already for years with a simple search on this newsgroup.

Cor

"Michel Posseth [MCP]" <MSDN@posseth.com> schreef in bericht
news:%23otnsgGvHHA.3640@TK2MSFTNGP05.phx.gbl...
> well i mention exchange explicitly cause i had some problems myself with
> it some time ago
[quoted text clipped - 102 lines]
>>>
>>> End sub
Cor Ligthert [MVP] - 02 Jul 2007 18:21 GMT
I forgot the :-)

Cor

"Michel Posseth [MCP]" <MSDN@posseth.com> schreef in bericht
news:%23otnsgGvHHA.3640@TK2MSFTNGP05.phx.gbl...
> well i mention exchange explicitly cause i had some problems myself with
> it some time ago
[quoted text clipped - 102 lines]
>>>
>>> End sub

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



©2008 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.