email - Does the Win 10 UWP EmailMessage API support having an HTML body? -


i have tried following code send email universal windows platform app. works fine when use emailmessagebodykind::plaintext. however, indicated in code below, emailmessagebodykind::html seems launch email client no content. know else needs set work - documentation sparse 8 (

using namespace windows::storage::streams; using namespace windows::applicationmodel::email; using namespace windows::security::cryptography; auto bin = cryptographicbuffer::convertstringtobinary(     l"<html><body>this <b>is</b> text</body></html>",     binarystringencoding::utf16le); auto memstream = ref new inmemoryrandomaccessstream(); concurrency::create_task(memstream->writeasync(bin)).then(     [memstream](unsigned)     {         auto email = ref new emailmessage();         email->to->append(ref new emailrecipient(l"test@gmail.com"));         email->subject = l"email report";         auto randomaccessstreamreference = randomaccessstreamreference::createfromstream(memstream);         email->setbodystream(emailmessagebodykind::html, randomaccessstreamreference);         emailmanager::showcomposenewemailasync(email);     } ); 

well, got bad news you.

it not possible using emailmanager.showcomposenewemailasync

regarding using setbodystream emailmessagebodykind.html, have from msdn forum:

currently, emailmessagebodykind.html won't work create new html e-mail , there no other way workaround, i've checked internal resource, api used populating messages app server , save e-mail message local folder.

the thing is: emailmanager.showcomposenewemailasync uses mailto send message and, stated in some other question answered here:

section 2 of rfc 2368 says body field supposed in text/plain format, can't html.

however if use plain text it's possible modern mail clients render resulting link clickable link anyway, though.

that being said, you're relying on mail client render html you.
i've tested using windows 10 mail client, gmail , outlook (both later on web browser), , of them failed render simple html <b> tag on mail body, showing plain text instead.

now, alternatives (from that same msdn forum thread):

note if use sharedatacontract (datatransfermanager), able set html in request , appear in email body if user chooses share via mail. skip share ui , go directly composing email recipient populated, html body, , image attachments.

one alternative persist html body file , include file additional attachment, not ideal

the datatransfermanager formatted html message. here's small sample of how sample code like, adapted from msdn:

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); } 

the limitations of approach are:

  1. you cannot force user select e-mail sharing option
  2. you cannot specify mail recipient.

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -