我必须创建电子邮件并将其保存在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
更多推荐
发布评论