【问题标题】:Sending email from Windows Phone 7 application从 Windows Phone 7 应用程序发送电子邮件
【发布时间】:2014-02-17 17:44:30
【问题描述】:

在我的 Windows Phone 7 应用程序中,我想发送一封电子邮件,其中邮件正文应包含我在应用程序中的上一页中的数据。以前我只是像这样集成电子邮件工具:

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

但我无法在我的模拟器中进行测试。现在在body 部分,我想要上一页的数据。那么该怎么做呢?

更新代码:

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

现在我在消息正文中写什么?我无法测试它,因为我没有设备。 我可以传递这样的值吗:

emailComposeTask.Body = "title, ndes, date";

【问题讨论】:

    标签: c# windows-phone-7


    【解决方案1】:

    我认为代码是正确的。如果要传递上一页的正文,则需要在页面导航时传递它。并设置 emailComposeTask.Body = yourPassedValue。 像这样:

    var date;
    var title;
    var ndes;
    
    emailComposeTask.Body = title + "," + ndes + "," + date;
    

    【讨论】:

    • 请看我更新的代码。是这样写的吗?
    • 您好,我已经回答了您关于短信的新问题。请阅读。
    【解决方案2】:

    您需要像这样编辑您的消息正文行:

    emailComposeTask.Body = title+" "+ ndes+" "+ date;
    

    【讨论】:

      【解决方案3】:

      您无法在模拟器中测试发送邮件,因为您没有设置正确的电子邮件帐户。也不能在模拟器中设置。

      Body 属性是一个字符串,因此您可以在其中放入几乎任何您想要的内容。

      使用以下代码只会生成一个包含该内容的字符串:

      emailComposeTask.Body = "title, ndes, date";
      

      因此,结果邮件的正文将包含“标题,ndes,日期”作为文本。如果要将标题替换为名为@9​​87654323@ 的局部变量中的值,则需要使用以下语法:

      emailComposeTask.Body = string.Format("{0}, {1}, {2}", title, nodes, date);
      

      【讨论】:

        猜你喜欢
        • 2013-02-04
        • 1970-01-01
        • 1970-01-01
        • 2014-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-08
        • 2020-05-24
        相关资源
        最近更新 更多