By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Windows service and outlook

P: n/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

Jul 1 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/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
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/

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"AMP" <al***@penstonall.co.ukwrote in message
news:11*********************@q69g2000hsb.googlegro ups.com...
>

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
Jul 1 '07 #2

P: n/a

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
"AMP" <al***@penstonall.co.ukschreef in bericht
news:11*********************@q69g2000hsb.googlegro ups.com...
>

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

Jul 1 '07 #3

P: n/a
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]" <MS**@posseth.comschreef in bericht
news:e4**************@TK2MSFTNGP03.phx.gbl...
>
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
"AMP" <al***@penstonall.co.ukschreef in bericht
news:11*********************@q69g2000hsb.googlegro ups.com...
>>

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


Jul 2 '07 #4

P: n/a
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]" <MS**@posseth.comschreef in bericht
news:e4**************@TK2MSFTNGP03.phx.gbl...
>
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
"AMP" <al***@penstonall.co.ukschreef in bericht
news:11*********************@q69g2000hsb.googlegro ups.com...
>>

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


Jul 2 '07 #5

P: n/a
I forgot the :-)

Cor

"Michel Posseth [MCP]" <MS**@posseth.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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]" <MS**@posseth.comschreef in bericht
news:e4**************@TK2MSFTNGP03.phx.gbl...
>>
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
"AMP" <al***@penstonall.co.ukschreef in bericht
news:11*********************@q69g2000hsb.googlegr oups.com...
>>>

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



Jul 2 '07 #6

P: n/a
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]" <MS**@posseth.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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]" <MS**@posseth.comschreef in bericht
news:e4**************@TK2MSFTNGP03.phx.gbl...
>>
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
"AMP" <al***@penstonall.co.ukschreef in bericht
news:11*********************@q69g2000hsb.googlegr oups.com...
>>>

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



Jul 2 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.