script-lab
script-lab copied to clipboard
How to send email from Excel Script Lab?
I am wondering how to send email from Excel Script Lab.
You need to implement the send mail logic by yourself, and call it in the code. Below is an example. I have a powerautomate flow, and exposed as a http webhook.
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
const payload = {
to: "change to you email address",
subject: "test",
body: "body"
};
const url =
"https://prod-26.southeastasia.logic.azure.com:443/workflows/8b05f53246ee40658e6d493fa74267f6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=kuo9GHih2PSeTsO0bHp-1o5P77sUNYVnecI9NOvgBTY";
await fetch(url, {
method: "post",
body: JSON.stringify(payload),
headers: {
"content-type": "application/json"
}
}).then((res) => console.log(res.status));
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
This is a great question for Stack Overflow with the office-js tag.