新的Outlook MailItem保存在收件箱而不是草稿(New Outlook MailItem saving in Inbox rather than Drafts)

编程入门 行业动态 更新时间:2024-10-08 10:51:32
新的Outlook MailItem保存在收件箱而不是草稿(New Outlook MailItem saving in Inbox rather than Drafts)

我必须创建电子邮件并将其保存在Outlook(2007)草稿文件夹中。 我使用Perl(ActivePerl 5.12.3)和Win32 :: OLE模块。 如果Outlook已经打开它可以正常工作。 Elsif我实例化Outlook,第一封电子邮件保存在收件箱中,其余邮件保存在“草稿”文件夹中。 以下说明了这个问题。

use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; my $oMailer; # Connect to a running version of Outlook eval { $oMailer = Win32::OLE->GetActiveObject('Outlook.Application') }; die "Outlook not installed" if $@; # Start up Outlook if not running unless(defined $oMailer) { $oMailer = new Win32::OLE('Outlook.Application', sub {$_[0]->Quit;}) or die "Unable to start an Outlook instance: $!\n"; } for (my $i=1; $i <5; $i++) { my $oEmail = $oMailer->CreateItem(0) or die "Unable to create mail item: $!\n"; $oEmail->{'To'} = 'me@domain.info'; $oEmail->{'Subject'} = "This is test #$i"; $oEmail->{BodyFormat} = olFormatHTML; $oEmail->{HTMLBody} = '<html></html>'; $oEmail->save(); }

MailItem.Save上的M $ dox说:

将Microsoft Outlook项目保存到当前文件夹,或者,如果是新项目,则保存到项目类型的Outlook默认文件夹。

我在google搜索工作中无法找到任何其他报告。 知道怎么让它按照记录的方式工作?

I have to create emails and save them in an Outlook (2007) Drafts folder. I am using Perl (ActivePerl 5.12.3) and the Win32::OLE module. If Outlook is already open it works correctly. Elsif I instantiate Outlook, the first email saves in the Inbox and the rest in the Drafts folder. The following demonstrates the problem.

use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; my $oMailer; # Connect to a running version of Outlook eval { $oMailer = Win32::OLE->GetActiveObject('Outlook.Application') }; die "Outlook not installed" if $@; # Start up Outlook if not running unless(defined $oMailer) { $oMailer = new Win32::OLE('Outlook.Application', sub {$_[0]->Quit;}) or die "Unable to start an Outlook instance: $!\n"; } for (my $i=1; $i <5; $i++) { my $oEmail = $oMailer->CreateItem(0) or die "Unable to create mail item: $!\n"; $oEmail->{'To'} = 'me@domain.info'; $oEmail->{'Subject'} = "This is test #$i"; $oEmail->{BodyFormat} = olFormatHTML; $oEmail->{HTMLBody} = '<html></html>'; $oEmail->save(); }

The M$ dox on MailItem.Save say:

Saves the Microsoft Outlook item to the current folder or, if this is a new item, to the Outlook default folder for the item type.

I have been unable to find any other reports of this in my googling efforts. Any idea of how to get it to work as documented?

最满意答案

这表示您从未登录过MAPI会话。

创建Outlook.Application对象的实例后,立即检索Namespace对象(Application.GetNamespace(“MAPI”),然后调用Namespace.Logon

This is an indication that you never logged to a MAPI session.

Immediately after creating an instance of the Outlook.Application object, retrieve the Namespace object (Application.GetNamespace("MAPI"), then call Namespace.Logon

更多推荐

本文发布于:2023-08-01 19:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1364649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收件箱   草稿   而不是   MailItem   Outlook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!