使用js使用EWS在outlook中发送电子邮件
Sending Email in outlook using EWS using js
我可以向用户发送邮件但是附件文件不符合要求。 接收者只接收主题和正文,没有附件。我应该怎么做才能让它也发送附件。此外,人们收到的邮件将自动变成垃圾邮件。
参考-
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 操作的完整列表,请参阅此 link:
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.
我可以向用户发送邮件但是附件文件不符合要求。 接收者只接收主题和正文,没有附件。我应该怎么做才能让它也发送附件。此外,人们收到的邮件将自动变成垃圾邮件。 参考-
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 操作的完整列表,请参阅此 link:
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.