3

I need to send an email with a log file from my windows phone 8.1 app. I found this 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);

Is there a special parameter to specify the attach file or another completly different way ?

Community
  • 1
  • 1
tufekoi
  • 929
  • 2
  • 14
  • 33
  • I used the DataTransferManager to prepare the content and then let the user choose an email app, I succeed to set the title of the mail : `request.Data.Properties.Title = loger.GetFileName();` but not the destination. Any help ? – tufekoi May 15 '15 at 09:59

1 Answers1

6

You should be able to use EmailMessage class for this. A sample code can look like this:

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
}
Romasz
  • 29,662
  • 13
  • 79
  • 154
  • Thanks a lot ! I though it was not possible to use those classes... I read the Windows.ApplicationModel.Email namespace since it just says that "The functionality described in this topic is not available to all Windows and Windows Phone apps. For your code... etc" – tufekoi May 15 '15 at 11:52
  • The accepted answer will not attach email to any win32 email application such as Outlook. attaching to email will only work with Windows Mail app-store app – pixel Oct 05 '17 at 16:57