javascript - 使用 js 使用 EWS 在 Outlook 中发送电子邮件
问题描述
我可以将邮件发送给用户,但附件文件不符合请求。接收者只接收主题和身体,没有附件。我应该怎么做才能发送附件。人们收到的邮件也会自动变成垃圾邮件。参考-
https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/createattachment
function send_mail(msg){
console.log(msg);
var request = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
' <soap:Header><t:RequestServerVersion Version="Exchange2010" /></soap:Header>'+
' <soap:Body>'+
' <m:CreateItem MessageDisposition="SendAndSaveCopy">'+
' <m:SavedItemFolderId><t:DistinguishedFolderId Id="sentitems" /></m:SavedItemFolderId>'+
' <m:Items>'+
' <t:Message>'+
' <ItemId Id="123" />'+
' <t:Subject>'+ msg.subject+'</t:Subject>'+
' <t:Body BodyType="HTML">'+msg.body +'</t:Body>'+
' <t:ToRecipients>'+
' <t:Mailbox><t:EmailAddress>' +msg.To + '</t:EmailAddress></t:Mailbox>'+
' </t:ToRecipients>'+
' </t:Message>'+
' </m:Items>'+
' </m:CreateItem>'+
' <CreateAttachment xmlns="https://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">'+
' <ParentItemId Id="123"/>'+
' <Attachments>'+
' <t:ItemAttachment>'+
' <t:Name>MyAttachment</t:Name>'+
' <t:Message>'+
' <t:ItemClass></t:ItemClass>'+
' <t:Subject>My attachment subject</t:Subject>'+
' <t:Body BodyType="Text">My attachment body</t:Body>'+
' </t:Message>'+
' </t:ItemAttachment>'+
' </Attachments>'+
' </CreateAttachment>'+
' </soap:Body>'+
' </soap:Envelope>';
Office.context.mailbox.makeEwsRequestAsync(request, function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Error" + asyncResult.error.message)
// showMessage("Action failed with error: ");
}
else {
console.log("Message Sent")
// showMessage("Message sent!");
}
});
解决方案
在您的 SOAP 请求中,您正在调用CreateAttachment
EWS 操作。在加载项的上下文中运行 EWS 时不支持此操作。有关受支持的 EWS 操作的完整列表,请参阅此链接:
https ://docs.microsoft.com/en-us/office/dev/add-ins/outlook/web-services
考虑使用 REST/Microsoft Graph,而不是使用 EWS。我们在这里有相关文档:https ://docs.microsoft.com/en-us/office/dev/add-ins/outlook/use-rest-api 。
推荐阅读
- python-3.x - 设置 django 进行部署
- python - 在 Python3 Flask Jinja2 模板中使用来自用户输入的参数调用函数
- powerbi - 使用条件筛选的 Power BI 度量
- python - flask-sqlalchemy:如何管理 SQL 视图?
- css - CSS/“完全”同一类的优先级较低
- python - WxPython ScrolledWindow 滚动条 - 如何使明显更大?
- python - 无法在 django 中的 url 末尾剪切斜线
- python - 如何在python中附加/连接不相关的数据帧
- python - 如何从 PDF 内容中提取(十六进制编码)文本?
- android - 从考虑android中删除状态栏