Reputation: 448
In my Windows Phone 7 application I want to send an e-mail where the message body should contain the data from my previous page in my application. Previously I just integrated the e-mail facility like this:
private void Image_Email(object sender, RoutedEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "message subject";
emailComposeTask.Body = "message body";
emailComposeTask.To = "[email protected]";
emailComposeTask.Cc = "[email protected]";
emailComposeTask.Bcc = "[email protected]";
emailComposeTask.Show();
}
But I was not able to test this in my emulator. Now in the body
part I want my data from the previous page. So how to do this?
Updated code:
if (this.NavigationContext.QueryString.ContainsKey("Date_Start"))
{
//if it is available, get parameter value
date = NavigationContext.QueryString["Date_Start"];
datee.Text = date;
}
if (this.NavigationContext.QueryString.ContainsKey("News_Title"))
{
//if it is available, get parameter value
ntitle = NavigationContext.QueryString["News_Title"];
title.Text = ntitle;
}
if (this.NavigationContext.QueryString.ContainsKey("News_Description"))
{
ndes = NavigationContext.QueryString["News_Description"];
description.Text = ndes;
}
Now what do I write in the message body? I am not able to test it as I do not have a device. Can i pass in the values like this:
emailComposeTask.Body = "title, ndes, date";
Upvotes: 1
Views: 168
Reputation: 7112
You cannot test sending mail in the emulator since you don't have a proper email account set up. Nor you could set it up in the emulator.
The Body
property is a string so you can put inside pretty much anything you want.
Using the following code will only generate a string containing exactly that:
emailComposeTask.Body = "title, ndes, date";
So the result mail will have a body containing "title, ndes, date" as a text. If you want to replace the title with the value from the local variable named title
, you need to use the following syntax:
emailComposeTask.Body = string.Format("{0}, {1}, {2}", title, nodes, date);
Upvotes: 1
Reputation: 146
You need to edit your message body line like this:
emailComposeTask.Body = title+" "+ ndes+" "+ date;
Upvotes: 1
Reputation: 8231
I think the code is correct. if you want to pass body from previous page, you need to pass it when page navigation. and set emailComposeTask.Body = yourPassedValue. like this:
var date;
var title;
var ndes;
emailComposeTask.Body = title + "," + ndes + "," + date;
Upvotes: 1