I want to send an email and saved the 'sent' version to c:\ drive
I can kind of achieved something like what I want by using 3 vb scripts (1 calling script and 2 scripts)(see below) BUT I needed to add a wait which works fine unless the email contains an attachment, it's the sleep that causes the problem here as if sending hasn't finished it saves the last sent item
I tried adding saveas to the Application_ItemSend it did save but only the draft version
I tried ItemAdd but nothing happened
I want to be able to do everything in one script without the sleep, it needs to happen after the .send and get the sent version rather than the draft version
I'm happy to explore c# or vb.net if it's a better way to do this ?
Here tr the scripts
Script 1 = this calls script 2 (send email) then waits a couple of seconds and calls script 3 save sent mail
Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "C:\script2.vbs"
WScript.Sleep 2000
objShell.Run "C:\script3.vbs"
Set objShell = Nothing
Script 2 - this sends email
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "me@myemail.com"
.Subject = "xsubjectline"
.ReadReceiptRequested = False
.HTMLBody = "Test Body text"
'.save
End With
'MyItem.Attachments.Add("c:\attachment.xls")
'msgbox(MyItem.Sent)
MyItem.Send
' I try to do something with MyItem here but what ever I do it returns NULL and errors, I guess MyItem no longer exists after the .send
Script 3
Dim objOutlook
Dim objDoc
Dim myNameSpace
Dim MyLastSentMessage
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set myNameSpace = objOutlook.GetNameSpace("MAPI")
Set MyLastSentMessage = myNameSpace.GetDefaultFolder(5).items(1)
'MyLastSentMessage.Display
MyLastSentMessage.SaveAs("c:\lastsentitem.msg")
Set objDoc = Nothing
Set objOutlook = Nothing
Set myNameSpace = Nothing
Set MyLastSentMessage = Nothing
any suggestions would be very appreciated
Thannk in advance
I can kind of achieved something like what I want by using 3 vb scripts (1 calling script and 2 scripts)(see below) BUT I needed to add a wait which works fine unless the email contains an attachment, it's the sleep that causes the problem here as if sending hasn't finished it saves the last sent item
I tried adding saveas to the Application_ItemSend it did save but only the draft version
I tried ItemAdd but nothing happened
I want to be able to do everything in one script without the sleep, it needs to happen after the .send and get the sent version rather than the draft version
I'm happy to explore c# or vb.net if it's a better way to do this ?
Here tr the scripts
Script 1 = this calls script 2 (send email) then waits a couple of seconds and calls script 3 save sent mail
Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "C:\script2.vbs"
WScript.Sleep 2000
objShell.Run "C:\script3.vbs"
Set objShell = Nothing
Script 2 - this sends email
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "me@myemail.com"
.Subject = "xsubjectline"
.ReadReceiptRequested = False
.HTMLBody = "Test Body text"
'.save
End With
'MyItem.Attachments.Add("c:\attachment.xls")
'msgbox(MyItem.Sent)
MyItem.Send
' I try to do something with MyItem here but what ever I do it returns NULL and errors, I guess MyItem no longer exists after the .send
Script 3
Dim objOutlook
Dim objDoc
Dim myNameSpace
Dim MyLastSentMessage
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set myNameSpace = objOutlook.GetNameSpace("MAPI")
Set MyLastSentMessage = myNameSpace.GetDefaultFolder(5).items(1)
'MyLastSentMessage.Display
MyLastSentMessage.SaveAs("c:\lastsentitem.msg")
Set objDoc = Nothing
Set objOutlook = Nothing
Set myNameSpace = Nothing
Set MyLastSentMessage = Nothing
any suggestions would be very appreciated
Thannk in advance