Ok, I have some bad news for you.
This cannot be done using EmailManager.ShowComposeNewEmailAsync
Regarding the use of SetBodyStream with EmailMessageBodyKind.Html , we have this from the MSDN forum:
Currently, EmailMessageBodyKind.Html will not work to create a new HTML email address, and there is no other way as a workaround, I checked the internal resource, this API is used to populate messages from the Application Server and save the email message in a local folder.
The fact is that EmailManager.ShowComposeNewEmailAsync uses mailto to send a message and, as indicated in another question already asked :
Section 2 of RFC 2368 says that the body field should be in text / plain, so you cannot do HTML.
However, even if you use plain text, itβs possible that some modern emails clients would have provided the resulting link as a clickable link anyway.
In doing so, you rely on the email client to display this HTML code for you.
I tested this using the Windows 10, Gmail and Outlook mail client (as later in the web browser), and all of them could not display a simple HTML <b> in the body of the message, showing it as plain text.
Now for alternatives (from the same MSDN forum forum ):
Please note that if I use ShareDataContract (DataTransferManager), I am able to set the HTML in the request, and it will appear in the letter if the user decides to share via Mail. However, I would like to skip the general user interface and go directly with composing the email with the recipient already filled in, the HTML body and image attachments.
One option is to save the HTML body to a file and then include this file as an additional application, however this is not ideal
DataTransferManager successfully formatted an HTML message. Here is a small example of what your sample code adapted from MSDN will look like:
void YourView::ShareHtml() { DataTransferManager^ dataTransferManager = DataTransferManager::GetForCurrentView(); auto dataRequestedToken = dataTransferManager->DataRequested += ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>( this, &YourView::OnShareHtml); DataTransferManager::ShowShareUI(); } void YourView::OnShareHtml(DataTransferManager^ sender, DataRequestedEventArgs^ e) { DataRequest^ request = e->Request; request->Data->Properties->Title = "Email Report"; String^ html = L"<html><body>this <b>is</b> text</body></html>"; String^ htmlFormat = HtmlFormatHelper::CreateHtmlFormat(html); request->Data->SetHtmlFormat(htmlFormat); }
Limitations of this approach are as follows:
- You cannot force the user to select email as a sharing option.
- You cannot pre-specify the mail recipient.