简体   繁体   English

电子邮件撰写任务无法正常工作Windows Phone 8.1

[英]email compose task is not working windows phone 8.1

how to send email in windows phone 8.1 app using a button ? 如何使用按钮在Windows Phone 8.1应用中发送电子邮件?

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

I'm getting error saying: 我收到错误消息:

"Error 1 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'." “错误1'await'运算符只能在异步方法中使用。请考虑使用'async'修饰符标记此方法,并将其返回类型更改为'Task'。”

You need to mark your event handler with the async keyword to be able to await inside it: 您需要使用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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM