Search code examples
javascriptoutlookoutlook-addinmailto

How to create a new email from an outlook add-in?


I would like to add a 'contact us' link or button in my taskpane add-in. I tried with a 'mailto' link approach which is not working properly : on the web, it launches the desktop default application ; on iOS, it opens a new email, but empty (no recipient) ; on Outlook desktop, it throws an alert because a web link tries to open a desktop application !

Is there a simple way to just create and open a new mail, in the currently used Outlook app, with prefilled fields, so the person has just to write its requests and send ? Info : my add-in is for Outlook 365 and written in JS.


Solution

  • EDIT:

    As of Office JS API level 1.6 displayNewMessageForm(parameters) method available. Method opens a form that enables the user to create a new message. If parameters are specified, the message form fields are automatically populated with the contents of the parameters.

    ORIGINAL ANSWER:

    Unfortunately Office.js API doesn't provide the functionality you are requesting. The API has Office.context.mailbox.displayMessageForm method to open existing message in read mode or Office.context.mailbox.item.displayReplyForm to display reply form for existing message; it provides ability to open new form to compose appointment Office.context.mailbox.displayNewAppointmentForm as well, but nothing for new compose form.

    If this is something you would like to see in upcoming releases you may describe your scenario at officespdev.uservoice.com

    Based on inability to use Office.js API as far as I can see you have 2 options:

    • Use as you described "mailto:" protocol to invoke new compose form (with all issues you have observed)
    • Crete a simple "contact us" form collect information and send it to your server with AJAX or server-side technology of your choice.