MoveTo not working in vb.net

MoveTo not working in vb.net

Post by John Zull » Wed, 18 Jun 2003 01:04:20



The following code in vb.net appears to run without error, but the messages
never move. Similar code works just fine in vbscript. Both programs are
included below. A search of google groups revealed many people having a
similar problem. Is  there a problem with the CDO Interpo in vb.net?

Thanks,
John Zullo
G-TRAC Development Group
GMS International Inc

Module Module1
  Sub Main()
    Dim oSession As MAPI.Session
    Dim oInfoStores As MAPI.InfoStores
    Dim oInfoStore As MAPI.InfoStore
    Dim oRootFolder As MAPI.Folder
    Dim oInbox As MAPI.Folder
    Dim oOther As MAPI.Folder
    Dim oMessages As MAPI.Messages
    Dim oMessage As MAPI.Message
    Dim oMovedMessage As MAPI.Message
    Dim oField As MAPI.Field
    Dim ProfileName As String
    Dim InfostoreName As String
    Dim MsgIx As Integer
    Dim AttIx As Integer
    Dim intCtr As Integer

    oSession = New MAPI.Session()
    ProfileName =
System.Configuration.ConfigurationSettings.AppSettings("ProfileName")
    oSession.Logon(ProfileName)
    InfostoreName =
System.Configuration.ConfigurationSettings.AppSettings("InfostoreName")
    oInfoStores = oSession.InfoStores
    oInfoStore = oInfoStores.Item(InfostoreName)
    oRootFolder = oInfoStore.RootFolder
    oInbox = oRootFolder.Folders("Inbox")
    oOther = oInbox.Folders("Temp")
    oMessages = oInbox.Messages
    MsgIx = oMessages.Count
    intCtr = 0
    Do While MsgIx > 0
        intCtr += 1
        oMessage = oMessages.Item(MsgIx)
        oMovedMessage = oMessage.MoveTo(oOther.FolderID, oOther.StoreID)
        oMovedMessage.Update(True, True)
        Console.WriteLine(oMovedMessage.Subject)
        MsgIx -= 1
        If intCtr > 1 Then Exit Sub
    Loop
  End Sub
End Module

Similar code in vbscript works fine.

<package>
<job>
<?job debug="true" error="true" ?>
<reference object="Cdo.Message" />
<script language="vbscript">
Option Explicit
Dim oSession
Dim oInfoStores
Dim oInfoStore
Dim oRootFolder
Dim oInbox
Dim oFolder
Dim oInfoStore2
Dim oRootFolder2
Dim oInbox2
Dim oFolder2
Dim strFolderId
Dim oItem
Dim oMessages
Dim oMEssage
Dim oMoveToMsg
Dim ix
Err.Clear
Set oSession = CreateObject("Mapi.Session")
oSession.Logon "Microsoft Outlook"
Set oInfoStores = oSession.InfoStores
'For Each oInfoStore in oInfoStores
' Msgbox oInfostore.Name
'next
Set oInfoStore = oInfoStores.Item("Mailbox - GtracMail ")
Set oRootFolder = oInfoStore.RootFolder
Set oInbox = oRootFolder.Folders("Inbox")
Set oFolder = oInbox
wscript.echo "Source " & oFolder.Name & " contains " &
oFolder.Messages.Count & " message(s)"
Set oInfoStore2 = oInfoStores.Item("Mailbox - GtracMail ")
Set oRootFolder2 = oInfoStore2.RootFolder
Set oInbox2 = oRootFolder2.Folders("Inbox")
set oFolder2 = oInbox2.Folders("Temp")
wscript.echo "Destination " & oFolder2.Name & " contains " &
oFolder2.Messages.Count & " message(s)"
WScript.Echo oFolder2.ID
Set oMessages = oFolder.Messages
ix = oMessages.Count
Do While ix > 0
Set oMessage = oMessages.Item(ix)
Set oMoveToMsg = oMessage.MoveTo(oFolder2.ID,oInfoStore2.ID)
oMoveToMsg.Update
ix = ix - 1
Loop
wscript.echo ix & " messages moved"
</script>
</job>
</package>

 
 
 

MoveTo not working in vb.net

Post by Siegfried Weber [MVP » Wed, 18 Jun 2003 14:23:59


1. What account does the VB.NET app use to run the code?
2. Does the profile you specify in the VB.NET code exists?
3. Does the account used to run the VB.NET code have proper permissions to
open the mailbox?

Also, I do not see a single try/catch to fetch eventually happening errors.
So, you might want to try:

oSession.Logon(ProfileName)
Try
  oInbox = oSession.Inbox
Catch ex As Exception
  Debug.Write("Error")
End Try

--
<Cheers:Siegfried runat="server" />

Development Lead,

CDOLive LLC - The Microsoft Messaging and Collaboration Application
Experts http://www.cdolive.com

This information is provided "AS IS" with no warranties, and confers no
rights. You assume all risk for your use. ? 2003 CDOLive LLC. All
rights reserved. Sample code subject to
http://www.cdolive.com/disclaim.htm


> The following code in vb.net appears to run without error, but the
> messages never move. Similar code works just fine in vbscript. Both
> programs are included below. A search of google groups revealed many
> people having a similar problem. Is  there a problem with the CDO
> Interpo in vb.net?

> Thanks,
> John Zullo
> G-TRAC Development Group
> GMS International Inc

> Module Module1
>   Sub Main()
>     Dim oSession As MAPI.Session
>     Dim oInfoStores As MAPI.InfoStores
>     Dim oInfoStore As MAPI.InfoStore
>     Dim oRootFolder As MAPI.Folder
>     Dim oInbox As MAPI.Folder
>     Dim oOther As MAPI.Folder
>     Dim oMessages As MAPI.Messages
>     Dim oMessage As MAPI.Message
>     Dim oMovedMessage As MAPI.Message
>     Dim oField As MAPI.Field
>     Dim ProfileName As String
>     Dim InfostoreName As String
>     Dim MsgIx As Integer
>     Dim AttIx As Integer
>     Dim intCtr As Integer

>     oSession = New MAPI.Session()
>     ProfileName =
> System.Configuration.ConfigurationSettings.AppSettings("ProfileName")
>     oSession.Logon(ProfileName)
>     InfostoreName =
> System.Configuration.ConfigurationSettings.AppSettings("InfostoreName")
>     oInfoStores = oSession.InfoStores
>     oInfoStore = oInfoStores.Item(InfostoreName)
>     oRootFolder = oInfoStore.RootFolder
>     oInbox = oRootFolder.Folders("Inbox")
>     oOther = oInbox.Folders("Temp")
>     oMessages = oInbox.Messages
>     MsgIx = oMessages.Count
>     intCtr = 0
>     Do While MsgIx > 0
>         intCtr += 1
>         oMessage = oMessages.Item(MsgIx)
>         oMovedMessage = oMessage.MoveTo(oOther.FolderID,
>         oOther.StoreID) oMovedMessage.Update(True, True)
>         Console.WriteLine(oMovedMessage.Subject)
>         MsgIx -= 1
>         If intCtr > 1 Then Exit Sub
>     Loop
>   End Sub
> End Module

> Similar code in vbscript works fine.

> <package>
> <job>
> <?job debug="true" error="true" ?>
> <reference object="Cdo.Message" />
> <script language="vbscript">
> Option Explicit
> Dim oSession
> Dim oInfoStores
> Dim oInfoStore
> Dim oRootFolder
> Dim oInbox
> Dim oFolder
> Dim oInfoStore2
> Dim oRootFolder2
> Dim oInbox2
> Dim oFolder2
> Dim strFolderId
> Dim oItem
> Dim oMessages
> Dim oMEssage
> Dim oMoveToMsg
> Dim ix
> Err.Clear
> Set oSession = CreateObject("Mapi.Session")
> oSession.Logon "Microsoft Outlook"
> Set oInfoStores = oSession.InfoStores
> 'For Each oInfoStore in oInfoStores
> ' Msgbox oInfostore.Name
> 'next
> Set oInfoStore = oInfoStores.Item("Mailbox - GtracMail ")
> Set oRootFolder = oInfoStore.RootFolder
> Set oInbox = oRootFolder.Folders("Inbox")
> Set oFolder = oInbox
> wscript.echo "Source " & oFolder.Name & " contains " &
> oFolder.Messages.Count & " message(s)"
> Set oInfoStore2 = oInfoStores.Item("Mailbox - GtracMail ")
> Set oRootFolder2 = oInfoStore2.RootFolder
> Set oInbox2 = oRootFolder2.Folders("Inbox")
> set oFolder2 = oInbox2.Folders("Temp")
> wscript.echo "Destination " & oFolder2.Name & " contains " &
> oFolder2.Messages.Count & " message(s)"
> WScript.Echo oFolder2.ID
> Set oMessages = oFolder.Messages
> ix = oMessages.Count
> Do While ix > 0
> Set oMessage = oMessages.Item(ix)
> Set oMoveToMsg = oMessage.MoveTo(oFolder2.ID,oInfoStore2.ID)
> oMoveToMsg.Update
> ix = ix - 1
> Loop
> wscript.echo ix & " messages moved"
> </script>
> </job>
> </package>


 
 
 

MoveTo not working in vb.net

Post by John Zull » Wed, 25 Jun 2003 05:20:01


1) The vb.net app is a console app that I run in debug mode from my
development account, the same account that the vbscript runs under.
2) When I run the vbscript, it says the profile doesn't exist, and I select
a profile from a dialogue box.
3) I have the mailbox opened as an additional mailbox in MS Outlook.
4) True there are no try/catch blocks at this time, but I am just single
stepping through code now to see if it will work.

Maybe something to do with point 2 above, but I don't see that dialogue box
pop up when running the vb.net version, and all the objects seem to exist
through the execution of the MoveTo instruction.



> 1. What account does the VB.NET app use to run the code?
> 2. Does the profile you specify in the VB.NET code exists?
> 3. Does the account used to run the VB.NET code have proper permissions to
> open the mailbox?

> Also, I do not see a single try/catch to fetch eventually happening
errors.
> So, you might want to try:

> oSession.Logon(ProfileName)
> Try
>   oInbox = oSession.Inbox
> Catch ex As Exception
>   Debug.Write("Error")
> End Try

> --
> <Cheers:Siegfried runat="server" />

> Development Lead,

> CDOLive LLC - The Microsoft Messaging and Collaboration Application
> Experts http://www.cdolive.com

> This information is provided "AS IS" with no warranties, and confers no
> rights. You assume all risk for your use. ? 2003 CDOLive LLC. All
> rights reserved. Sample code subject to
> http://www.cdolive.com/disclaim.htm


> > The following code in vb.net appears to run without error, but the
> > messages never move. Similar code works just fine in vbscript. Both
> > programs are included below. A search of google groups revealed many
> > people having a similar problem. Is  there a problem with the CDO
> > Interpo in vb.net?

> > Thanks,
> > John Zullo
> > G-TRAC Development Group
> > GMS International Inc

> > Module Module1
> >   Sub Main()
> >     Dim oSession As MAPI.Session
> >     Dim oInfoStores As MAPI.InfoStores
> >     Dim oInfoStore As MAPI.InfoStore
> >     Dim oRootFolder As MAPI.Folder
> >     Dim oInbox As MAPI.Folder
> >     Dim oOther As MAPI.Folder
> >     Dim oMessages As MAPI.Messages
> >     Dim oMessage As MAPI.Message
> >     Dim oMovedMessage As MAPI.Message
> >     Dim oField As MAPI.Field
> >     Dim ProfileName As String
> >     Dim InfostoreName As String
> >     Dim MsgIx As Integer
> >     Dim AttIx As Integer
> >     Dim intCtr As Integer

> >     oSession = New MAPI.Session()
> >     ProfileName =
> > System.Configuration.ConfigurationSettings.AppSettings("ProfileName")
> >     oSession.Logon(ProfileName)
> >     InfostoreName =
> > System.Configuration.ConfigurationSettings.AppSettings("InfostoreName")
> >     oInfoStores = oSession.InfoStores
> >     oInfoStore = oInfoStores.Item(InfostoreName)
> >     oRootFolder = oInfoStore.RootFolder
> >     oInbox = oRootFolder.Folders("Inbox")
> >     oOther = oInbox.Folders("Temp")
> >     oMessages = oInbox.Messages
> >     MsgIx = oMessages.Count
> >     intCtr = 0
> >     Do While MsgIx > 0
> >         intCtr += 1
> >         oMessage = oMessages.Item(MsgIx)
> >         oMovedMessage = oMessage.MoveTo(oOther.FolderID,
> >         oOther.StoreID) oMovedMessage.Update(True, True)
> >         Console.WriteLine(oMovedMessage.Subject)
> >         MsgIx -= 1
> >         If intCtr > 1 Then Exit Sub
> >     Loop
> >   End Sub
> > End Module

> > Similar code in vbscript works fine.

> > <package>
> > <job>
> > <?job debug="true" error="true" ?>
> > <reference object="Cdo.Message" />
> > <script language="vbscript">
> > Option Explicit
> > Dim oSession
> > Dim oInfoStores
> > Dim oInfoStore
> > Dim oRootFolder
> > Dim oInbox
> > Dim oFolder
> > Dim oInfoStore2
> > Dim oRootFolder2
> > Dim oInbox2
> > Dim oFolder2
> > Dim strFolderId
> > Dim oItem
> > Dim oMessages
> > Dim oMEssage
> > Dim oMoveToMsg
> > Dim ix
> > Err.Clear
> > Set oSession = CreateObject("Mapi.Session")
> > oSession.Logon "Microsoft Outlook"
> > Set oInfoStores = oSession.InfoStores
> > 'For Each oInfoStore in oInfoStores
> > ' Msgbox oInfostore.Name
> > 'next
> > Set oInfoStore = oInfoStores.Item("Mailbox - GtracMail ")
> > Set oRootFolder = oInfoStore.RootFolder
> > Set oInbox = oRootFolder.Folders("Inbox")
> > Set oFolder = oInbox
> > wscript.echo "Source " & oFolder.Name & " contains " &
> > oFolder.Messages.Count & " message(s)"
> > Set oInfoStore2 = oInfoStores.Item("Mailbox - GtracMail ")
> > Set oRootFolder2 = oInfoStore2.RootFolder
> > Set oInbox2 = oRootFolder2.Folders("Inbox")
> > set oFolder2 = oInbox2.Folders("Temp")
> > wscript.echo "Destination " & oFolder2.Name & " contains " &
> > oFolder2.Messages.Count & " message(s)"
> > WScript.Echo oFolder2.ID
> > Set oMessages = oFolder.Messages
> > ix = oMessages.Count
> > Do While ix > 0
> > Set oMessage = oMessages.Item(ix)
> > Set oMoveToMsg = oMessage.MoveTo(oFolder2.ID,oInfoStore2.ID)
> > oMoveToMsg.Update
> > ix = ix - 1
> > Loop
> > wscript.echo ix & " messages moved"
> > </script>
> > </job>
> > </package>

 
 
 

MoveTo not working in vb.net

Post by Siegfried Weber [MVP » Sat, 28 Jun 2003 06:13:05


Yes, I'd definitely say it is related to the missing profile. Any reason why
not using a dynamic profile instead?

--
<Cheers:Siegfried runat="server" />

Development Lead,

CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
http://www.cdolive.com

This information is provided "AS IS" with no warranties, and confers no
rights.
You assume all risk for your use. ? 2003 CDOLive LLC. All rights reserved.
Sample code subject to http://www.cdolive.com/disclaim.htm


> 1) The vb.net app is a console app that I run in debug mode from my
> development account, the same account that the vbscript runs under.
> 2) When I run the vbscript, it says the profile doesn't exist, and I
select
> a profile from a dialogue box.
> 3) I have the mailbox opened as an additional mailbox in MS Outlook.
> 4) True there are no try/catch blocks at this time, but I am just single
> stepping through code now to see if it will work.

> Maybe something to do with point 2 above, but I don't see that dialogue
box
> pop up when running the vb.net version, and all the objects seem to exist
> through the execution of the MoveTo instruction.



>> 1. What account does the VB.NET app use to run the code?
>> 2. Does the profile you specify in the VB.NET code exists?
>> 3. Does the account used to run the VB.NET code have proper permissions
to
>> open the mailbox?

>> Also, I do not see a single try/catch to fetch eventually happening
errors.
>> So, you might want to try:

>> oSession.Logon(ProfileName)
>> Try
>>   oInbox = oSession.Inbox
>> Catch ex As Exception
>>   Debug.Write("Error")
>> End Try

>> --
>> <Cheers:Siegfried runat="server" />

>> Development Lead,

>> CDOLive LLC - The Microsoft Messaging and Collaboration Application
>> Experts http://www.cdolive.com

>> This information is provided "AS IS" with no warranties, and confers no
>> rights. You assume all risk for your use. ? 2003 CDOLive LLC. All
>> rights reserved. Sample code subject to
>> http://www.cdolive.com/disclaim.htm


>>> The following code in vb.net appears to run without error, but the
>>> messages never move. Similar code works just fine in vbscript. Both
>>> programs are included below. A search of google groups revealed many
>>> people having a similar problem. Is  there a problem with the CDO
>>> Interpo in vb.net?

>>> Thanks,
>>> John Zullo
>>> G-TRAC Development Group
>>> GMS International Inc

>>> Module Module1
>>>   Sub Main()
>>>     Dim oSession As MAPI.Session
>>>     Dim oInfoStores As MAPI.InfoStores
>>>     Dim oInfoStore As MAPI.InfoStore
>>>     Dim oRootFolder As MAPI.Folder
>>>     Dim oInbox As MAPI.Folder
>>>     Dim oOther As MAPI.Folder
>>>     Dim oMessages As MAPI.Messages
>>>     Dim oMessage As MAPI.Message
>>>     Dim oMovedMessage As MAPI.Message
>>>     Dim oField As MAPI.Field
>>>     Dim ProfileName As String
>>>     Dim InfostoreName As String
>>>     Dim MsgIx As Integer
>>>     Dim AttIx As Integer
>>>     Dim intCtr As Integer

>>>     oSession = New MAPI.Session()
>>>     ProfileName =
>>> System.Configuration.ConfigurationSettings.AppSettings("ProfileName")
>>>     oSession.Logon(ProfileName)
>>>     InfostoreName =
>>> System.Configuration.ConfigurationSettings.AppSettings("InfostoreName")
>>>     oInfoStores = oSession.InfoStores
>>>     oInfoStore = oInfoStores.Item(InfostoreName)
>>>     oRootFolder = oInfoStore.RootFolder
>>>     oInbox = oRootFolder.Folders("Inbox")
>>>     oOther = oInbox.Folders("Temp")
>>>     oMessages = oInbox.Messages
>>>     MsgIx = oMessages.Count
>>>     intCtr = 0
>>>     Do While MsgIx > 0
>>>         intCtr += 1
>>>         oMessage = oMessages.Item(MsgIx)
>>>         oMovedMessage = oMessage.MoveTo(oOther.FolderID,
>>>         oOther.StoreID) oMovedMessage.Update(True, True)
>>>         Console.WriteLine(oMovedMessage.Subject)
>>>         MsgIx -= 1
>>>         If intCtr > 1 Then Exit Sub
>>>     Loop
>>>   End Sub
>>> End Module

>>> Similar code in vbscript works fine.

>>> <package>
>>> <job>
>>> <?job debug="true" error="true" ?>
>>> <reference object="Cdo.Message" />
>>> <script language="vbscript">
>>> Option Explicit
>>> Dim oSession
>>> Dim oInfoStores
>>> Dim oInfoStore
>>> Dim oRootFolder
>>> Dim oInbox
>>> Dim oFolder
>>> Dim oInfoStore2
>>> Dim oRootFolder2
>>> Dim oInbox2
>>> Dim oFolder2
>>> Dim strFolderId
>>> Dim oItem
>>> Dim oMessages
>>> Dim oMEssage
>>> Dim oMoveToMsg
>>> Dim ix
>>> Err.Clear
>>> Set oSession = CreateObject("Mapi.Session")
>>> oSession.Logon "Microsoft Outlook"
>>> Set oInfoStores = oSession.InfoStores
>>> 'For Each oInfoStore in oInfoStores
>>> ' Msgbox oInfostore.Name
>>> 'next
>>> Set oInfoStore = oInfoStores.Item("Mailbox - GtracMail ")
>>> Set oRootFolder = oInfoStore.RootFolder
>>> Set oInbox = oRootFolder.Folders("Inbox")
>>> Set oFolder = oInbox
>>> wscript.echo "Source " & oFolder.Name & " contains " &
>>> oFolder.Messages.Count & " message(s)"
>>> Set oInfoStore2 = oInfoStores.Item("Mailbox - GtracMail ")
>>> Set oRootFolder2 = oInfoStore2.RootFolder
>>> Set oInbox2 = oRootFolder2.Folders("Inbox")
>>> set oFolder2 = oInbox2.Folders("Temp")
>>> wscript.echo "Destination " & oFolder2.Name & " contains " &
>>> oFolder2.Messages.Count & " message(s)"
>>> WScript.Echo oFolder2.ID
>>> Set oMessages = oFolder.Messages
>>> ix = oMessages.Count
>>> Do While ix > 0
>>> Set oMessage = oMessages.Item(ix)
>>> Set oMoveToMsg = oMessage.MoveTo(oFolder2.ID,oInfoStore2.ID)
>>> oMoveToMsg.Update
>>> ix = ix - 1
>>> Loop
>>> wscript.echo ix & " messages moved"
>>> </script>
>>> </job>
>>> </package>

 
 
 

1. MoveTo method not working - MAPI_E_NO_SUPPORT

I am trying to move a message through VBScript (Exchange Event) code from
the Sent Items folder to another folder on the same mailbox.  The code is as
follows:

Set oMovedMsg = oMsgTarget.MoveTo(oFolder.Id,oInfoStore.Id)

I get a MAPI_E_NO_SUPPORT error on this line.  There are values for
oFolderId and oInfoStore.Id.  Any ideas?  I am running Exchange 5.5.

Peter

2. User gets blank messages

3. Asp.Net VB.Net Emailing from code using Specific Account

4. Creating a Distribution List on Exchange 5.5

5. Creating Exchange Users in VB or VB.NET

6. New mail notification

7. VB.NET: Specified cast is not valid.

8. Spinning my wheels

9. Event script MoveTo works CopyTo doesn't

10. Exchange Not Working Over Net

11. Internexus.net news pull not working

12. Remote Mail not working for 'Net mail

13. Net Folders Through Exchange Server to Internet Mail Recipient Does Not Work