Reputation: 1
I am writing a very data intensive Metro App where I need to send an email in html format. After googling around I came across this code.
var mailto = new Uri("mailto:[email protected]&subject=The subject of an email&body=Hello from a Windows 8 Metro app.");
await Windows.System.Launcher.LaunchUriAsync(mailto);
This works great for me with one exception. I am generating the body of this email via html string so I have code in my class like this.
string htmlString=""
DALClient client = new DALClient();
htmlString += "<html><body>";
htmlString += "<table>";
List<People> people = client.getPeopleWithReservations();
foreach(People ppl in people)
{
htmlString+="<tr>"
htmlString +="<td>" + ppl.PersonName + "</td>";
htmlString +="</tr>";
}
htmlString +="</table>";
htmlString +="</body><html>";
Now when I run this code the email client opens up. However the result appears as plain text. Is there a way I can have this show up in the formatted html so the html tags and so forth wont display? Thanks in advance.
Upvotes: 0
Views: 845
Reputation: 3023
It is just not possible to pass HTML to mailto. You could use sharing instead where you can pass HTML code to the default Windows Store Mail App (unfortunately not to the default Desktop Mail Application).
Here is a sample on a page:
public sealed partial class MainPage : Page
{
private string eMailSubject;
private string eMailHtmlText;
...
private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
// Check if an email is there for sharing
if (String.IsNullOrEmpty(this.eMailHtmlText) == false)
{
// Pass the current subject
args.Request.Data.Properties.Title = this.eMailSubject;
// Pass the current email text
args.Request.Data.SetHtmlFormat(
HtmlFormatHelper.CreateHtmlFormat(this.eMailHtmlText));
// Delete the current subject and text to avoid multiple sharing
this.eMailSubject = null;
this.eMailHtmlText = null;
}
else
{
// Pass a text that reports nothing currently exists for sharing
args.Request.FailWithDisplayText("Currently there is no email for sharing");
}
}
...
// "Send" an email
this.eMailSubject = "Test";
this.eMailHtmlText = "Hey,<br/><br/> " +
"This is just a <b>test</b>.";
DataTransferManager.ShowShareUI();
Another approach would be to use SMTP but as far as I know there is no SMTP implementation yet for Windows Store Apps.
Upvotes: 1