Windows service and outlook

A

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

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
 
J

Jay B. Harlow [MVP - Outlook]

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/
 
M

Michel Posseth [MCP]

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
 
C

Cor Ligthert [MVP]

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
 
M

Michel Posseth [MCP]

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
 
C

Cor Ligthert [MVP]

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
 
C

Cor Ligthert [MVP]

I forgot the :)

Cor

Michel Posseth said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top