Blog
Email - How to open a new Outlook mail message and pre-populate the subject and message
April 24. 2021
In cases where we want create a new Outlook mail message and to pre-populate the recipient, subject and email body, we can accomplish this by calling the Launch function and specifying a "mailto" URL. This post describes this technqiue in more detail.
There are several ways to send email messages from Power Apps. The most popular way is to use the Office365 Outlook connector, as outlined in my post beneath:
This connector provides a SendEmailV2 method that enables us to compose and to send an email completely from within an app.
In cases where users use the desktop version of Microsoft Outlook or some other local email client, there may be a requirement to initiate the creation of a new mail message from Power Apps, and to pre-populate to recipient, subject, and body of the message.
We can accomplish this by calling the Launch function from Power Apps, and constructing a URL that follows the "mailto:" convention. A "mailto:" address takes the following format:
In cases where users use the desktop version of Microsoft Outlook or some other local email client, there may be a requirement to initiate the creation of a new mail message from Power Apps, and to pre-populate to recipient, subject, and body of the message.
We can accomplish this by calling the Launch function from Power Apps, and constructing a URL that follows the "mailto:" convention. A "mailto:" address takes the following format:
mailto:recipientaddress@email.com?subject=EmailSubject&body=EmailBody
Let's assume that we build a screen that contains three text input controls - txtRecipient, txtSubject, and txtBody.
We can build this feature by adding a button and setting the OnSelect property to the following formula.
Launch("mailto:" & txtRecipient.Text &
"?subject=" & EncodeUrl(txtSubject.Text) &
"&body=" & EncodeUrl(txtBody.Text)
)
An important point is that it's necessary to call the EncodeURL function here to escape any special characters. For instance, if the email body text includes the "&" character (which is the character that separates parameters in the web address), not using code URL function will result in the truncation of the message. EncodeURL will also correctly replace space characters with the %20 escape sequence.
When the user clicks the button, Microsoft Outlook (or the registered email client) will open and display a new email message with the to, subject, and email body fields populated. The user can edit this message further, before manually sending it.
Conclusion
We can create a new email message in a local copy of Microsoft
Outlook (or some other email client) and pre-populate the to, subject, and body fields by calling the Launch function and specifying a
"mailto" URL.
- Categories:
Related posts
- Email - Complete guide to validating email addresses
- Bug - Sending email messages with the Office365Outlook connector that includes SharePoint file attachments no longer works
- Email - Sending messages with SMTP connector
- Email - How to save multiple email addresses in a field, and configure the selection and display of addresses through a combo box
- Email - How to send email without the Office 365 Outlook connector (using the Mail connector)
- Email - How to send mail with the Gmail connector