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:
- Open Outlook Online or Outlook for the web.
- Create a new email or reply to an existing email.
- Click on the “Automate” tab in the ribbon.
- Click on the “Script Lab” button.
- In the Script Lab pane, create a new script or open an existing one.
- Replace the default code in the script editor with the code provided above.
- 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.