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