简体   繁体   English

如何使用C#从Outlook中删除电子邮件?

[英]How to delete an email from Outlook using C#?

I can successfully retrieve and read emails from Outlook using the following code. 我可以使用以下代码从Outlook成功检索和阅读电子邮件。 How can I delete an email from Outlook? 如何从Outlook中删除电子邮件? I have tried several ways but couldn't get it to work. 我尝试了几种方法,但无法正常工作。

var svc = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
svc.Credentials = CredentialCache.DefaultNetworkCredentials;
svc.AutodiscoverUrl(emailAddress);
EmailMessage email = EmailMessage.Bind(svc, emailMessage.Id, props);

I'm not sure (ie, may be proven incorrect) that you can delete messages using this API. 我不确定(即可能被证明不正确)您可以使用此API 删除邮件。 The MSDN article for Microsoft.Exchange.Data.Transport.Email Namespace says this: 有关Microsoft.Exchange.Data.Transport.Email命名空间MSDN文章说:

The Microsoft.Exchange.Data.Transport.Email namespace contains types that support creating, reading, writing, and modifying e-mail message. Microsoft.Exchange.Data.Transport.Email命名空间包含支持创建,读取,编写和修改电子邮件的类型。

And further inspection of the members available on the EmailMessage class suggest you can access various properties, but there's no "delete" operation/method available. 进一步检查EmailMessage类上可用的成员,建议您可以访问各种属性,但是没有“删除”操作/方法。

Depending on your scenario, you might have better luck using a tool like Outlook Redemption which will allow low-level programmatic access to Outlook and/or Exchange (but may not be appropriate if you need to go via exchange web services). 根据您的情况,使用Outlook Redemption之类的工具可能会比较幸运,该工具将允许对Outlook和/或Exchange进行低级编程访问(但如果需要通过Exchange Web服务进行访问,则可能不合适)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM