Hello,
I have an issue with sending an email in my backend is taking a 30 second or more so it cause me a late response to my request in client
my code
const sendMail = async data => {
const POLLER_WAIT_TIME = 10
try {
const message = {
senderAddress: `<${data.From.Email}>`,
content: {
subject: data.Subject,
html: data.HTMLPart,
},
recipients: {
to: [
{
address: `<${data.To[0].Email}>`,
displayName: `<${data.To[0].Name}>`,
},
],
},
};
const poller = await emailClient.beginSend(message);
if (!poller.getOperationState().isStarted) {
throw "Poller was not started."
}
let timeElapsed = 0;
while (!poller.isDone()) {
poller.poll();
console.log("Email send polling in progress");
await new Promise(resolve => setTimeout(resolve, POLLER_WAIT_TIME * 1000));
timeElapsed += 10;
if (timeElapsed > 18 * POLLER_WAIT_TIME) {
console.log("Polling timed out.");
return true
}
}
if (poller.getResult().status === KnownEmailSendStatus.Succeeded) {
console.log(`Successfully sent the email (operation id: ${poller.getResult().id})`);
return true;
}
else {
console.log(poller.getResult().error);
return true
}
} catch (e) {
console.log(e);
}
};