Microsoft Exchange Web 服务确保电子邮件发送成功

Microsoft Exchange Web Services make sure email sent successfully

有没有办法确保我通过 Microsoft Exchange Web 服务发送的电子邮件已成功发送?这是我使用的代码:

        var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
        {
            Credentials = new WebCredentials(EmailFrom, Password),
            Url = new Uri(ExchangeUrl),
        };

        var email = new EmailMessage(service)
        {
            Subject = "Test",
            Body = "Hello from .net!",
        };

        email.ToRecipients.Add(EmailTo);

        email.Send();

在 EWS 中发送是异步的,因此当您 运行 发送时,您将得到的只是提交的状态。因为您甚至没有将已发送消息保存到 SentItem 文件夹中,所以唯一的方法可能是在发送之前设置 Internet MessageId,然后在服务器上的跟踪日志中跟踪消息

    ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
    EmailMessage ema = new EmailMessage(service);
    ema.Subject ="test from ews";
    ema.Body = new MessageBody("test<br>Rgds<>");
    ema.ToRecipients.Add("gscales@domain.com");
    ema.SetExtendedProperty(PidTagInternetMessageId,("<" +Guid.NewGuid().ToString() + "@domain.com>"));
    ema.Send();