OfficeScripts to send email using outlook account

To send an email using an Outlook account in OfficeScripts, you can utilize the Office.context.mailbox.item object. Here’s an example of an OfficeScript that sends an email using an Outlook account:

function main() {
  // Create the email message
  var email = Office.context.mailbox.item;
  email.subject = "Test Email";
  email.body.setHtmlBody("<b>This is a test email.</b>");

  // Set the recipients
  email.to.addEmailAddress("[email protected]");
  email.to.addEmailAddress("[email protected]");

  // Send the email
  email.send();
}

To use this OfficeScript, follow these steps:

  1. Open Outlook Online or Outlook for the web.
  2. Create a new email or reply to an existing email.
  3. Click on the “Automate” tab in the ribbon.
  4. Click on the “Script Lab” button.
  5. In the Script Lab pane, create a new script or open an existing one.
  6. Replace the default code in the script editor with the code provided above.
  7. Click the “Run” button to execute the script.

This script uses the Office.context.mailbox.item object to access the current email message. It sets the subject and body of the email using the subject and body properties. You can customize the subject and body content as needed. The recipients are added using the to.addEmailAddress() method, where you can specify one or more email addresses. Finally, the send() method is called to send the email.

Please note that OfficeScripts are currently only supported in Outlook for the web. They are not available in the desktop version of Outlook. Additionally, you need to have an active Outlook account configured in your Office 365 or Exchange Online environment to send emails.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech