Create an "Inbox" looking Mail Item in another folder

  • Thread starter Mark Ham via OfficeKB.com
  • Start date
M

Mark Ham via OfficeKB.com

I have the following Visual Basic .Net code. I tried Redemption (yesterday) and still do not quite understand it. I want to create a mail item that looks like it came into the "Inbox" and was moved to a specific folder. I want to populate the mail item with data from a flat text file. I do not want it to look like a draft ready to be sent out. Here is my code:

' Create a new MailItem object
Dim newMail As Outlook.MailItem

' Assign values to the newMail MailItem
newMail = objFolder.Items.Add(Outlook.OlItemType.olMailItem)
newMail.Subject = "My test subject"
newMail.Body = "The test body of the email"
newMail.To = "xxx"
newmail.SenderEmailAddress = "yyy" <- this does not work!
' So I have to use this
newMail.SentOnBehalfOfName = "yyy"
newMail.Move(objFolder)


The problem is, it ends up on the new folder as a Draft with "On Behalf of yyy". I cannot set the "ReceivedTime", flag that it was Sent, or any of the fields to make it look like an "Inbox" email.

If anyone can help I will greatly appreciated it,
Thanks in advance,

Hammer
 
K

Ken Slovak - [MVP - Outlook]

You can't make an item look sent without sending it or receiving it. Take a
look at the Object Browser for the Outlook properties you are trying to use
and you will see that many of them are read-only.




Mark Ham via OfficeKB.com said:
I have the following Visual Basic .Net code. I tried Redemption
(yesterday) and still do not quite understand it. I want to create a mail
item that looks like it came into the "Inbox" and was moved to a specific
folder. I want to populate the mail item with data from a flat text file.
I do not want it to look like a draft ready to be sent out. Here is my
code:
' Create a new MailItem object
Dim newMail As Outlook.MailItem

' Assign values to the newMail MailItem
newMail = objFolder.Items.Add(Outlook.OlItemType.olMailItem)
newMail.Subject = "My test subject"
newMail.Body = "The test body of the email"
newMail.To = "xxx"
newmail.SenderEmailAddress = "yyy" <- this does not work!
' So I have to use this
newMail.SentOnBehalfOfName = "yyy"
newMail.Move(objFolder)


The problem is, it ends up on the new folder as a Draft with "On Behalf of
yyy". I cannot set the "ReceivedTime", flag that it was Sent, or any of the
fields to make it look like an "Inbox" email.
 
D

Dmitry Streblechenko \(MVP\)

Actually you can create an olPostItem (created in the sent state), change
its MessageClass property to "IPM.Note", dereference it, then reopen it
using Namespace.GetItemfromID - you will get back a newly created MailItem
in the sent state.
The icon might still look wrong, so you will need to reset the PR_ICON_INDEX
property using Extended MAPI/CDO/Redemption.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top