如何使用 JavaScript 从交换服务器获取电子邮件内容作为 EML 或 MSG?
How to get the email content as EML or MSG from the exchange server using JavaScript?
我想在我的 Node
应用程序中获取 .msg
格式的电子邮件内容。目前我发送以下 SOAP 请求以获取电子邮件的 html 版本:
const getEmailContentSOAP = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<RequestServerVersion Version="Exchange2013"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
<GetItem
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
<t:IncludeMimeContent>true</t:IncludeMimeContent>
</ItemShape>
<ItemIds>
<t:ItemId Id="${emailID}" />
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>`;
有没有办法直接获取 .msg 版本或将其转换为 .msg?
不,MSG 格式是一种 Office 文件格式(复合文件格式 https://en.wikipedia.org/wiki/Compound_File_Binary_Format,生成起来并不容易)所以通常使用 Outlook 或 Redemption 是唯一可行的方法,也是唯一真正的原因人们通常尝试使用 MSG 格式是为了保持 MAPI 属性和附件类型的保真度,您将需要 MAPI。
对于你使用 EWS 所做的事情,你使用 IncludeMimeContent 返回的内容是消息的 MIMEConent,它可以保存为 EML 文件,因此可以在任何支持 EML 的电子邮件客户端(包括 Outlook)中打开,这通常就足够了对于大多数事情(不包括迁移)。
正如 Glen 所说,生成 EML 格式的电子邮件。我已经这样做了,它适用于不同的邮件客户端(SharePoint 也有 .eml 文件的预览模式!)。
我建议你使用Microsoft Graph API获取所有邮件数据,这样你就可以生成.eml邮件。
API调用示例获取带有附件的单个邮件数据:
`https://graph.microsoft.com/v1.0/me/messages/${messageId}?$expand=attachments`
然后转换它。
您有更多可用数据:
它处于测试阶段,没有文档,但您可以使用 Microsoft Graph 获取 MIME 内容 API:
GET https://graph.microsoft.com/beta/me/messages/{id}/$value
或
GET https://graph.microsoft.com/beta/users/{id | userPrincipalName}/messages/{id}/$value
您可以尝试 Graph Explorer,将版本设置为 beta。
然后您可以将响应保存为.eml 文件。
编辑:
现已正式预览:https://docs.microsoft.com/en-us/graph/outlook-get-mime-message
我想在我的 Node
应用程序中获取 .msg
格式的电子邮件内容。目前我发送以下 SOAP 请求以获取电子邮件的 html 版本:
const getEmailContentSOAP = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<RequestServerVersion Version="Exchange2013"
xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
<GetItem
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
<t:IncludeMimeContent>true</t:IncludeMimeContent>
</ItemShape>
<ItemIds>
<t:ItemId Id="${emailID}" />
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>`;
有没有办法直接获取 .msg 版本或将其转换为 .msg?
不,MSG 格式是一种 Office 文件格式(复合文件格式 https://en.wikipedia.org/wiki/Compound_File_Binary_Format,生成起来并不容易)所以通常使用 Outlook 或 Redemption 是唯一可行的方法,也是唯一真正的原因人们通常尝试使用 MSG 格式是为了保持 MAPI 属性和附件类型的保真度,您将需要 MAPI。
对于你使用 EWS 所做的事情,你使用 IncludeMimeContent 返回的内容是消息的 MIMEConent,它可以保存为 EML 文件,因此可以在任何支持 EML 的电子邮件客户端(包括 Outlook)中打开,这通常就足够了对于大多数事情(不包括迁移)。
正如 Glen 所说,生成 EML 格式的电子邮件。我已经这样做了,它适用于不同的邮件客户端(SharePoint 也有 .eml 文件的预览模式!)。
我建议你使用Microsoft Graph API获取所有邮件数据,这样你就可以生成.eml邮件。
API调用示例获取带有附件的单个邮件数据:
`https://graph.microsoft.com/v1.0/me/messages/${messageId}?$expand=attachments`
然后转换它。
您有更多可用数据:
它处于测试阶段,没有文档,但您可以使用 Microsoft Graph 获取 MIME 内容 API:
GET https://graph.microsoft.com/beta/me/messages/{id}/$value
或
GET https://graph.microsoft.com/beta/users/{id | userPrincipalName}/messages/{id}/$value
您可以尝试 Graph Explorer,将版本设置为 beta。
然后您可以将响应保存为.eml 文件。
编辑:
现已正式预览:https://docs.microsoft.com/en-us/graph/outlook-get-mime-message