c# - 如何查看邮件是否发送成功或取消?

标签 c# outlook

我这样创建 Outlook 邮件:

 Outlook.Application outlookApp = new Outlook.Application();
 Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
 mailItem.Subject = mailSubject;
 mailItem.To = "";
 mailItem.Attachments.Add(totalPath);
 mailItem.Body = mailBody;
 mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
 mailItem.Display(true);
 //Mail is send succesfully?

是否可以查询邮件是否发送成功或取消?

当我执行下面的代码时,出现错误

'the item is moved or deleted'

Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = mailSubject;
mailItem.To = "";
mailItem.CC = "EDI.Orders@trust.com";
mailItem.Attachments.Add(totalPath);
mailItem.Body = mailBody;
mailItem.Importance = Outlook.OlImportance.olImportanceNormal;
mailItem.Display(true);
//Mail is send succesfully?
if (mailItem.Sent)
{
   MessageBox.Show("Sended");
}
else
{
   MessageBox.Show("canceled");
}

错误出现在 mailItem.Sent

最佳答案

mailItem.Sent 属性显示电子邮件是否已发送。

此外,您可以附加到 mailItem.Write 事件。 (但要小心 - 也会在保存等时被调用)

mailItem.Write += mailItem_Write;

void mailItem_Write(ref bool Cancel)
    {
       //your code...
    }

关于c# - 如何查看邮件是否发送成功或取消?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30343737/

相关文章:

c# - 在 Controller 级别设置 NullValueHandling

c# - 创建一个假的虚拟驱动器(以处理对该驱动器的文件 I/O)

c++ - 预览 Microsoft Outlook 对象库生成的电子邮件

HTML 电子邮件图像在链接上反转单击 Outlook 07/10/13

c# - 找不到类型或命名空间名称 'VibrationDevice'

c# - 如何清除任务缓存?

c# - 删除使用 C# 创建的 Outlook 约会并更新 Outlook 类别

java - 如何使用 Apache POI - HSMF 提取嵌套到另一个 Outlook 消息中?

c# - 系统.TypeLoadException : Could not resolve type with token 01000019

c# - Outlook 返回错误 : The messaging interface has returned an unknown error