I’m trying to create a mailitem and save it in the Drafts folder for an other user. I can create the draft but it only saves to my own draft folder, not for the other user. I have enough rights on the mailbox of the other user.
This is my test code so far:
Dim omApp As New Outlook.Application
Dim omNamespace As Outlook.NameSpace = omApp.GetNamespace("MAPI")
Dim omUser As Outlook.Recipient = omNamespace.CreateRecipient("otheruser@mail.com")
omUser.Resolve()
If Not omUser.Resolved Then
MsgBox("Could not login.")
End If
Dim omDrafts As Outlook.MAPIFolder = omNamespace.GetSharedDefaultFolder(omUser, Outlook.OlDefaultFolders.olFolderDrafts)
Dim omMailItem As Outlook.MailItem = CType(omDrafts.Items.Add, Outlook.MailItem)
With omMailItem
.SentOnBehalfOfName = "otheruser@mail.com"
.To = "bill@gates.com"
.Subject = "Test"
.Body = "Test email"
.Save()
End With
What am I doing wrong?
The code has to work for all Outlook versions from 2003 to 2010.
Ok, I’ve solved it myself. After the “Save” I add a “Move” to move it from my Drafts folder to the user’s shared folder. So the code will be: