发送带有附件 WinRT 的电子邮件

Send email with attach file WinRT

我需要发送一封电子邮件,其中包含来自我的 windows phone 8.1 应用程序的日志文件。我发现这个 way :

var mailto = new Uri("mailto:?to=recipient@example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app."); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

是否有一个特殊的参数来指定附加文件或其他完全不同的方式?

您应该可以使用 EmailMessage class 来完成此操作。示例代码如下所示:

private async void SendBtn_Click(object sender, RoutedEventArgs e)
{
    EmailMessage email = new EmailMessage { Subject = "Sending test file" };
    email.To.Add(new EmailRecipient("myMailbox@mail.com"));

    // Create a sample file to send
    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("testFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
    await FileIO.WriteTextAsync(file, "Something inside a file");

    email.Attachments.Add(new EmailAttachment(file.Name, file)); // add attachment
    await EmailManager.ShowComposeNewEmailAsync(email); // send email
}