473,692 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows service and 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

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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

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.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start()

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub

Jul 1 '07 #1
6 4753
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._Applic ation = New Outlook.Applica tion()
Can anyone tell me whats wroung
Simple.

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

oMsg = CreateObject("R edemption.SafeM ailItem")
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***@penstona ll.co.ukwrote in message
news:11******** *************@q 69g2000hsb.goog legroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

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.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start()

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub
Jul 1 '07 #2

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***@penstona ll.co.ukschreef in bericht
news:11******** *************@q 69g2000hsb.goog legroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

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.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start()

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub

Jul 1 '07 #3
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.c omschreef in bericht
news:e4******** ******@TK2MSFTN GP03.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***@penstona ll.co.ukschreef in bericht
news:11******** *************@q 69g2000hsb.goog legroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

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.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start( )

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub


Jul 2 '07 #4
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.c omschreef in bericht
news:e4******** ******@TK2MSFTN GP03.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***@penstona ll.co.ukschreef in bericht
news:11******** *************@q 69g2000hsb.goog legroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

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.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start( )

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub


Jul 2 '07 #5
I forgot the :-)

Cor

"Michel Posseth [MCP]" <MS**@posseth.c omschreef in bericht
news:%2******** ********@TK2MSF TNGP05.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.c omschreef in bericht
news:e4******** ******@TK2MSFTN GP03.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***@penstona ll.co.ukschreef in bericht
news:11******* **************@ q69g2000hsb.goo glegroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

oMsg.item = oApp.CreateItem (0)

oMsg.Subjec t = pvsubject

oMsg.Body = pvmessage & vbCr & vbCr

oMsg.To = pvsendto

' ' Add an attachment

Dim sSource As String = pvattachment

If pvattachment <"" Then

Dim oAttachs As Outlook.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start ()

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub



Jul 2 '07 #6
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.c omschreef in bericht
news:%2******** ********@TK2MSF TNGP05.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.c omschreef in bericht
news:e4******** ******@TK2MSFTN GP03.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***@penstona ll.co.ukschreef in bericht
news:11******* **************@ q69g2000hsb.goo glegroups.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._Applic ation = New Outlook.Applica tion()

Dim oNS As Outlook._NameSp ace = oApp.GetNamespa ce("mapi")

Dim oSyncs As Outlook.SyncObj ects

Dim oSync As Outlook.SyncObj ect

Try

' Reference SyncObjects.

oSyncs = oNS.SyncObjects

oSync = oSyncs.Item("Al l Accounts")

' Create a new MailItem.

Dim oMsg

oMsg = CreateObject("R edemption.SafeM ailItem")

oMsg.item = oApp.CreateItem (0)

oMsg.Subjec t = pvsubject

oMsg.Body = pvmessage & vbCr & vbCr

oMsg.To = pvsendto

' ' Add an attachment

Dim sSource As String = pvattachment

If pvattachment <"" Then

Dim oAttachs As Outlook.Attachm ents = oMsg.Attachment s

Dim oAttach As Outlook.Attachm ent

oAttach = oAttachs.Add(sS ource)

End If

' ' Send

oMsg.Send()

oSync.Start ()

Catch ex As Exception

' Console.WriteLi ne(ex.Message)

' Me.EventLog.Wri teEntry(ex.Mess age)

End Try

End sub



Jul 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3049
by: Paul | last post by:
I am using a windows service which accesses Microsoft Outlook. Outlook is supposed to send an email. This works fine when not run in a windows service. I am running the service under my user domain logon. I am using VB.net and using redemption.dll to bypass the security patch. This is the line of code that causes the event error Dim olApp As New Outlook.Application When I try and use a service the following error occurs.
0
2026
by: W Akthar | last post by:
Hi All, I have created a simple Windows Service which needs to be able to send appointments to Outlook. I have no problem makeing a reference to Microsoft Outlook 11.0 Object Library and compiling the code. the problem arises when I try to install the service using installutil. The error message I get is the following
3
2345
by: W Akthar | last post by:
Hi I am trying to create a windows service which queries SQL Server on timed intervals and depending on the results send appointments to Outlook. The problem lies when I try to create an outlook application object.
2
3542
by: W Akthar | last post by:
Hi All, I have written a windows service which runs a small windows application. This windows application queries a sql server database and depending on these results, sets appointments in outlook. When I run the windows application outside the service it works fine as designed, but when it is launched from a windows service I get an error message
2
1201
by: Dima Protchenko | last post by:
Hi, I am building a windows service, which monitors a mailbox and parses email messages into the db. When I wrote the SAME code in windows forms application, everything worked fine, but I am having a problem in the Windows Service project and I can't figure it out. For i As Integer = objFolder.Items.Count To 1 Step -1 If TypeOf (objFolder.Items.Item(i)) Is Outlook.MailItem Then 'Me.EventLog.WriteEntry("TechLocatorSRVC", "Sender :" &...
3
2503
by: THNQDigital | last post by:
Hi All, I have written VB.NET Windows Service whcih reads some information from Outlook and creates an Excel report outa it. When i make a console application and run the program everything works fine but same code does not work if i put it in an Windows service. My OS : Win2000 Pro
9
2799
by: Phil G. | last post by:
Hi all, I would like to create a very simple 'lite' version of Outlook Calendar's reminder function. I will use a windows service that will read timedate stamps from a db and compare them to Now. This seems that it will create a lot of processor overhead in terms of 'how often shall I check the db?'. I wonder if I check it hourly and save additional info. as a timespan...I just don't know......has anyone got any ideas of best practice...
3
5871
by: sokolo | last post by:
Hello, I wrote a windows service application however it is not working. The service is supposed to enter a new task every 5 sec within Microsoft Outlook. Here is the code for application: public partial class CheckAccountsService : ServiceBase {
0
1386
by: piotrperak | last post by:
I asked it on Outlook group too, but maybe some of You had similiar problems. I am using CDO. Using it I was able to access Inbox and Sent Items of: Outlook 2003 from Windows app and Windows Service on WinXP Outlook 2000 only from Windows app on Win2000 When running Session.Logon as a service I receive ].
0
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8549
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9094
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8970
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8814
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2989
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.