[英]Sending email from Windows Phone 7 application
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. 在我的Windows Phone 7应用程序中,我想发送一封电子邮件,其中邮件正文应包含我的应用程序中上一页的数据。 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 = "recipient@example.com";
emailComposeTask.Cc = "cc@example.com";
emailComposeTask.Bcc = "bcc@example.com";
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. 现在在body
部分我想要上一页的数据。 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";
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. 并设置emailComposeTask.Body = yourPassedValue。 like this: 像这样:
var date;
var title;
var ndes;
emailComposeTask.Body = title + "," + ndes + "," + date;
您需要像这样编辑邮件正文行:
emailComposeTask.Body = title+" "+ ndes+" "+ date;
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. Body
属性是一个字符串,因此您可以放入任何您想要的内容。
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. 因此,结果邮件将包含一个包含“title,ndes,date”的正文作为文本。 If you want to replace the title with the value from the local variable named title
, you need to use the following syntax: 如果要使用名为title
的局部变量中的值替换标题,则需要使用以下语法:
emailComposeTask.Body = string.Format("{0}, {1}, {2}", title, nodes, date);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.