【发布时间】:2012-04-26 01:00:45
【问题描述】:
我创建了一个小型 C# 控制台应用程序来使用非常简单的 Outlook 发送邮件
Outlook.Application oApp = new Outlook.Application();
//Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.Recipients.Add("xxx@xxx.com"); //////////////////problem line
oMsg.Subject = "aaaa";
oMsg.Body = "body";
//Send the message.
oMsg.Save();
oMsg.Send();
此代码需要从php代码中调用。
1) 它可以在控制台中正常工作。
2) 当我从 php 调用时,我得到一个错误。我注意到从 php 调用此控制台应用程序时会在系统用户中运行。所以我让outlook作为系统运行,但我仍然得到这个错误。我正在运行 Apache 服务器。
System.Runtime.InteropServices.COMException (0x80004004):操作中止(来自 HRESULT 的异常:0x80004004 (E_ABORT)) 在 Microsoft.Office.Interop.Outlook._MailItem.get_Recipients() 在 D:\NotEncrypted\Projects\SyncEmail\SyncEmail\Program.cs:line 121 中的 SyncEmail.Program.sendMailUsingOutlook(字符串收件人,字符串正文,字符串主题)处
我正在拔头发,看着不同的东西。任何帮助,将不胜感激。感谢您阅读我的帖子。
在我说有些人说使用 php 之后,我决定走 php 路线并编写此代码并得到相同的错误。
if (!defined(‘olMailItem’)) define(“olMailItem”,0);
$objApp = new COM(“Outlook.Application”);
$myItem = $objApp->CreateItem(olMailItem);
$myItem->To=’xxxx@xxx.com’;
$myItem->SentOnBehalfOfName = ‘yyy@xxyyx.com’;
$myItem->Subject=”This is a test”;
$myItem->Body=”This is a Body Section now…..!”;
$myItem->Send();
我收到这个错误
致命错误:第 11251 行的 D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php 中带有消息的未捕获异常“com_exception” (!) com_exception: Error [0x80004004] Operation aborted in D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php 第 11251 行
【问题讨论】: