简体   繁体   English

在非默认文件夹中创建Outlook电子邮件

[英]Create Outlook email in non-default folder

I'm trying to create an Outlook email in a non-default folder using Delphi: 我正在尝试使用Delphi在非默认文件夹中创建Outlook电子邮件:

procedure NewMail;
var
  ParentFolder, Myfolder:  MAPIFolder;
  MyMail: MailItem;

begin
  Parentfolder := MAPI.GetDefaultFolder(olFolderInbox).Parent as MAPIFolder;
  MyFolder := ParentFolder.Folders.Item('MyMessages') as MAPIFolder;
  MyMail := MyFolder.Items.Add(olMailItem) as MailItem;
  MyMail.Save;
  MyMail.Display(false);
end;

The mail item is displayed, but does not appear in the non-default folder. 显示邮件项目,但未显示在非默认文件夹中。 The folder is good (I can copy emails to it manually, and get items.count programatically). 该文件夹很好(我可以手动将电子邮件复制到该文件夹​​,并以编程方式获取items.count)。 If I use the same code for a non-default tasks folder it works fine, so it appears to be something particular about an email folder. 如果我对非默认任务文件夹使用相同的代码,则可以正常工作,因此它似乎与电子邮件文件夹有关。 Grateful for any suggestions. 感谢任何建议。 Thanks, Paul. 谢谢,保罗。

Outlook has an annoying habit of creating messages in the default folder even if you explicitly specify a different folder. 即使您明确指定了其他文件夹,Outlook也有在默认文件夹中创建邮件的烦人习惯。 Try to move the message there: 尝试将消息移到那里:

MyMail := MyFolder.Items.Add(olMailItem) as MailItem;
MyMail := MyMail.Move(MyFolder);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM