提取电子邮件信息

显示电子邮件元数据

MailMessage represents an email message and allows developers to access its properties. The header information can be extracted and manipulated in different ways. This article explains how to display selected email header information and the email body on the screen. To display email information on the screen, follow these steps:

  • 创建该类的实例 MailMessage 类。
  • 将电子邮件消息加载到 MailMessage 实例。
  • 在屏幕上显示电子邮件内容。

下面的代码片段展示了如何在屏幕上显示电子邮件信息:

提取电子邮件头

电子邮件头部是由 Internet 和 RFC 定义的标准头字段集合,包含在电子邮件消息中。可以使用 MailMessage 类指定电子邮件头部。常见的头部类型在 HeaderType class 的实例中加载电子邮件消息。它是一个封闭类,像典型的枚举一样工作。要从电子邮件中提取头部,请按照以下步骤操作:

  1. 创建该类的实例 MailMessage 类。
  2. MailMessage 类。
  3. 在加载电子邮件消息后,我们将获取其原始内容。

MailMessage class 本身包含 From、To、Cc、Subject 等属性。这些属性可以从头部中提取。

下面的代码片段展示了如何提取电子邮件头部:

解码头部值

下面的代码片段展示了如何获取解码后的头部值。