发送电子邮件附带文件WinRT

本文关键字:文件 WinRT 电子邮件 | 更新日期: 2023-09-27 17:49:16

我需要从我的windows phone 8.1应用程序发送一封带有日志文件的电子邮件。我发现这种方式:

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

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

发送电子邮件附带文件WinRT

您应该能够使用EmailMessage类。示例代码如下所示:

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
}