如何使用按钮在Windows Phone 8.1 app中发送电子邮件?
EmailRecipient sendTo = new EmailRecipient()
{
Address = "abc@outlook.com"
};
//generate mail object
EmailMessage mail = new EmailMessage();
mail.Subject = "Feedback";
//add recipients to the mail object
mail.To.Add(sendTo);
//mail.Bcc.Add(sendTo);
//mail.CC.Add(sendTo);
//open the share contract with Mail only:
await EmailManager.ShowComposeNewEmailAsync(mail);
我收到错误说:
"错误1' await'运算符只能在异步方法中使用。 考虑使用' async'标记此方法。修饰和改变 它的返回类型为'任务'。"
答案 0 :(得分:1)
您需要使用async
关键字标记您的事件处理程序,以便能够在其中await
:
public async void MyButtonHandler(object sender, EventArgs e)
{
EmailRecipient sendTo = new EmailRecipient()
{
Address = "abc@outlook.com"
};
//generate mail object
EmailMessage mail = new EmailMessage();
mail.Subject = "Feedback";
//add recipients to the mail object
mail.To.Add(sendTo);
//mail.Bcc.Add(sendTo);
//mail.CC.Add(sendTo);
//open the share contract with Mail only:
await EmailManager.ShowComposeNewEmailAsync(mail);
}