Reputation: 1
I'm developing an Outlook add-in that reports phishing emails using Exchange Web Services (EWS) on an Exchange On-Premises server. The add-in workflow includes a backend (Express) for handling authentication and sending the email report. Below is the code for both my backend and frontend.
const express = require('express');
const cors = require('cors');
const app = express();
app.use(express.json());
app.use(cors());
app.post('/api/report-phishing', async (req, res) => {
const { subject, sender } = req.body;
// Construct the SOAP envelope for EWS
const soapEnvelope = `...`; //// Full SOAP XML
const token = 'token'; //// Placeholder
try {
const response = await fetch('https://exchange.example.ch/ews/Exchange.asmx', {
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'Authorization': `Bearer ${token}`,
},
body: soapEnvelope,
});
if (response.ok) {
res.send({ success: true, message: 'Phishing report sent successfully!' });
} else {
const errorText = await response.text();
res.status(500).send({ error: `Exchange server error: ${errorText}` });
}
} catch (error) {
console.error('Error communicating with Exchange server:', error);
res.status(500).send({ error: 'Internal server error while sending report.' });
}
});
app.listen(5000, () => {
console.log("Proxy server running on http://localhost:5000");
});
and
const reportPhishingWithBackend = async () => {
const item = Office.context.mailbox.item;
const data = {
subject: item.subject,
sender: item.from.emailAddress,
};
try {
const response = await fetch('http://localhost:5000/api/report-phishing', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
if (response.ok) {
alert('Phishing report sent successfully!');
} else {
const errorData = await response.json();
console.error('Failed to send report:', errorData.error);
alert('Failed to send phishing report. Check the console for details.');
}
} catch (error) {
console.error('Error:', error);
alert('Error sending phishing report.');
}
};
Problem: I encounter two errors when running the add-in: Failed to fetch (on the frontend) Connect Timeout Error (on the backend when connecting to the Exchange server) Questions: EWS Authentication: What is the best authentication method for EWS in an on-premises environment? (Currently using gettokenasync method to get token.) Connection Issues: How can I debug and resolve the "Connect Timeout" issue with EWS? Are there specific configurations needed for on-premises servers? Any guidance or best practices would be appreciated!
Upvotes: 0
Views: 19