473,915 Members | 5,813 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 4773
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
3065
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
2043
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
2362
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
3550
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
1207
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
2512
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
2807
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
5879
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
1415
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
10039
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
9881
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
10542
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
9732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7256
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5943
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
4778
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
3
3368
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.