webForumDet fria alternativet

Flytta mail mha vb-script och Outlook.Application

1 svar · 374 visningar · startad av devotion

devotionMedlem sedan jan. 20013 582 inlägg
#1

Hej,

Jag har knåpat ihop en liten kod som läser av information i ett mail i Outlook. Jag har fått till det så att informationen läses och mailet flyttas till borttaget. Nu vill jag dock flytta mailet till en speciell mapp. Men jag får felmeddelande enligt bifogad bild.

Sub main
	dim oOutlook, oSafeMailItem, oMailItem, oAttach, oDestFolder
	dim oNS, oInbox, oItem, oItems

	set oOutlook = CreateObject("Outlook.Application") 
	Set oSafeMailItem= CreateObject("Redemption.SafeMailItem")

	Set oNS=oOutlook.GetNamespace("MAPI")
	Set oInbox=oNS.GetDefaultFolder(6)
	Set oItems = oInbox.Items

	For Each oItem In oItems
		If oItem.Subject="Felanmälan" Then
			oSafeMailItem.Item=oItem
			If CreateTaskFromMailItem(oSafeMailItem)>=0 Then
				[B]oItem.Move (oInbox.Folders("Test"))[/B]
			End If
		End If
	Next
	
	Set oSafeMailItem=Nothing
	Set oInbox=Nothing
	Set oNS=Nothing
	Set oOutlook=Nothing
End Sub
oItem.Delete

...funkar...

Någon som har några bra idéer?

Mvh
Henrik

outlook.png
devotionMedlem sedan jan. 20013 582 inlägg
#2

Efter en hel del sökande och lite klurande så...

Sub main()
	dim oOutlook, oSafeMailItem, oMailItem, oAttach, oDestFolder
	dim oNS, oInbox, oItem, oItems

	set oOutlook = CreateObject("Outlook.Application") 
	Set oSafeMailItem= CreateObject("Redemption.SafeMailItem")

	Set oNS=oOutlook.GetNamespace("MAPI")
	Set oInbox=oNS.GetDefaultFolder(6)
	
	[B]Set oDestFolder=oNS.Folders("Postlåda - Henrik Lindell").Folders("Mottagna uppdrag")[/B]
	Set oItems = oInbox.Items

	For Each oItem In oItems
		If oItem.Subject="Felanmälan" Then
			oSafeMailItem.Item=oItem
			If CreateTaskFromMailItem(oSafeMailItem)>=0 Then
				oItem.Move oDestFolder
			End If
		End If
	Next
	
	Set oSafeMailItem=Nothing
	Set oInbox=Nothing
	Set oNS=Nothing
	Set oOutlook=Nothing
End Sub
125 ms totalt · 3 externa anrop · v20260731065814-full.fb544a5a
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
121 ms — hämta tråd, inlägg och bilagor (db)