admin管理员组文章数量:1122832
I am building a outlook addin where I need to send an email for phishing to specific exchange account using Exchange On-Premises via Exchange Web Services (EWS). I am trying to make a POST request to the EWS endpoint from the frontend, but I’m facing issues with connectivity and authentication.
What I’ve tried:
EWS Endpoint: .asmx Authentication: I am using basic authentication with a username and password. The request is sent with an XML body in the POST request. Error: I’m encountering a ConnectTimeoutError and fetch failed error while trying to connect to the server from the React app.
const sendEmail = async () => {
const EXCHANGE_URL = ".asmx";
const USERNAME = "[email protected]";
const PASSWORD = "password";
const xmlPayload = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="/" xmlns:t=";>
<soap:Header>
<t:RequestServerVersion Version="Exchange2016" />
</soap:Header>
<soap:Body>
<m:CreateItem xmlns:m="; xmlns:t=";>
<m:Items>
<t:Message>
<t:Subject>Test Email</t:Subject>
<t:Body BodyType="Text">This is a test email sent via EWS from React frontend.</t:Body>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>[email protected]</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</m:Items>
</m:CreateItem>
</soap:Body>
</soap:Envelope>`;
try {
const response = await fetch(EXCHANGE_URL, {
method: "POST",
headers: {
"Content-Type": "text/xml",
"Authorization": "Basic " + btoa(`${USERNAME}:${PASSWORD}`)
},
body: xmlPayload,
});
const data = await response.text();
console.log("Email sent successfully:", data);
} catch (error) {
console.error("Error connecting to Exchange:", error);
}
};
sendEmail();
I am building a outlook addin where I need to send an email for phishing to specific exchange account using Exchange On-Premises via Exchange Web Services (EWS). I am trying to make a POST request to the EWS endpoint from the frontend, but I’m facing issues with connectivity and authentication.
What I’ve tried:
EWS Endpoint: https://exchange.example.com/ews/Exchange.asmx Authentication: I am using basic authentication with a username and password. The request is sent with an XML body in the POST request. Error: I’m encountering a ConnectTimeoutError and fetch failed error while trying to connect to the server from the React app.
const sendEmail = async () => {
const EXCHANGE_URL = "https://exchange.example.com/ews/Exchange.asmx";
const USERNAME = "[email protected]";
const PASSWORD = "password";
const xmlPayload = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016" />
</soap:Header>
<soap:Body>
<m:CreateItem xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:Items>
<t:Message>
<t:Subject>Test Email</t:Subject>
<t:Body BodyType="Text">This is a test email sent via EWS from React frontend.</t:Body>
<t:ToRecipients>
<t:Mailbox>
<t:EmailAddress>[email protected]</t:EmailAddress>
</t:Mailbox>
</t:ToRecipients>
</t:Message>
</m:Items>
</m:CreateItem>
</soap:Body>
</soap:Envelope>`;
try {
const response = await fetch(EXCHANGE_URL, {
method: "POST",
headers: {
"Content-Type": "text/xml",
"Authorization": "Basic " + btoa(`${USERNAME}:${PASSWORD}`)
},
body: xmlPayload,
});
const data = await response.text();
console.log("Email sent successfully:", data);
} catch (error) {
console.error("Error connecting to Exchange:", error);
}
};
sendEmail();
Share
Improve this question
asked Nov 21, 2024 at 17:48
Shahzad UmarShahzad Umar
11 bronze badge
1 Answer
Reset to default 0What type of addin are you trying to build ? if its an old Com+ based addin then don't use EWS you better of just using the OOM to send it. With the newer addin framework you would normally use a Callback tokens https://learn.microsoft.com/en-gb/office/dev/add-ins/outlook/authentication?redirectedfrom=MSDN#callback-tokens and then use makeEwsRequestAsync https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/web-services this means the Auth and routing/discovery are all handled for you.
You could start with testing EWS using the EWSeditor https://github.com/dseph/EwsEditor/releases that allows you to test the authentication and connectivity outside of any code your writing.
本文标签: reactjsHow to send an email with Exchange OnPremises in outlook addinStack Overflow
版权声明:本文标题:reactjs - How to send an email with Exchange On-Premises in outlook addin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308277a1933603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论