How to send email in office 365 using office scripts or Excel Script

asked 2022-06-03T15:56:39.477+00:00
Benard Mwanza 981 Reputation points

I'm currently creating an office script to send email from excel online(hosted in onedriveforbusiness). The components of the email am extracting from excel cell values. Have done a research and it looks to me that office script has syntax similar to javascript or typescript. I'm also not sure if the language used is javascript or typescript, kindly clarify for me on that.

In summary

I need a code sample on how to send email from office script in excel online(office 365)
I need to know what language is being used in office script, is it javascript or typescript.

Below is the sample code office script have written and its failing when i run it.

function main(workbook: ExcelScript.Workbook) {  
    // Your code here  
  
  // select a sheet  
  let selected_sheet = workbook.getActiveWorksheet()  
  
  // get subject  
  let subject = selected_sheet.getRange("C2")  
  let subject_ = subject.getValue()  
  
  // get body  
  let body = selected_sheet.getRange("E2")  
  let body_ = body.getValue()  
  
  // to email  
  let receivembx = selected_sheet.getRange("B2")  
  let receivembx_ = receivembx.getValue()  
  
  // from email  
  let sendmbx = "emailhere"  
  let pwd_ = "passwordhere"  
  
  Email.send({  
    Host: "smtp.office365.com",  
    Username: sendmbx,  
    Password: pwd_,  
    To: receivembx_,  
    From: sendmbx,  
    Subject: subject_,  
    Body: body_,  
  
  }).then(  
    console.log("mail sent successfully")  
  );  

Below is the snip for the excel online and office script.
208218-snip.png

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
1,934 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
1,563 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,333 questions
{count} votes