Outlook现有邮件消息

时间:2014-10-27 14:54:22

标签: email types outlook

使用以下代码以编程方式创建新电子邮件时:

solutionRoot = rootStoreFolder.Folders.Add("MyInboxFolder", Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; 
folder = solutionRoot.Folders["MyFolderName"] as Outlook.Folder;
subFolder = folder.Folders["MyFolderSubName"] as Outlook.Folder;

Outlook.MailItem mailItem  = this.Application.CreateItem(Outlook.OlItemType.olMailItem)  as Outlook.MailItem;

mailItem.Subject = "TestSubject";
mailItem.To = "myEmailAddress@yahoo.com";                           
mailItem.Body = "This is the message.";
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(false);
mailItem.Move(subFolder);

结果是创建了一条新邮件,其中发送按钮放在文件夹子文件夹中。

问题是:我应该使用什么代码来创建一个名为subFolder的新邮件项目,而不是一个准备发送的新电子邮件,一封已经收到并阅读的电子邮件,现有的电子邮件。

1 个答案:

答案 0 :(得分:0)

Outlook不会让你创建一个开箱即用的发送消息(MailItem.Sent属性是只读的)。 在已发送状态中创建的唯一项是一个帖子项 - 您可以创建一个olPostItem对象(PostItem),然后将其MessageClass属性更改回IPM.Note。您还需要删除PR_ICON_INDEX属性以确保正确显示。请注意,无法使用OOM设置发送/接收日期。

如果使用Redemption是一个选项,则以下脚本(VB)将创建发送给当前用户的虚假接收消息:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Inbox = Session.GetDefaultFolder(olFolderInbox)
  set Msg = Inbox.Items.Add
  Msg.Sent = true
  set CU = Session.CurrentUser
  set recip = Msg.Recipients.AddEx(CU.Name, CU.SmtpAddress, "SMTP", olTo)
  Msg.Subject = "fake received message"
  Msg.Body = "just a test"
  vSenderEntryId = Session.AddressBook.CreateOneOffEntryID("Joe The Sender", "SMTP", "joe@domain.demo", false, true)
  set vSender = Session.AddressBook.GetAddressEntryFromID(vSenderEntryId)
  Msg.Sender = vSender
  Msg.SentOnBehalfOf = vSender
  Msg.SentOn = Now
  Msg.ReceivedTime = Now
  Msg.Save