Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email attachments via UWP EmailManager not working

Sending an attachment from a universal app with the following code is not working, why?

        Dim emailMessage As New EmailMessage()
        emailMessage.[To].Add(New EmailRecipient("[email protected]"))
        emailMessage.Subject = "Test"
        emailMessage.Body = "Hello World"

        Dim localAppFolder = Windows.Storage.ApplicationData.Current.LocalFolder
        Dim file = Await localAppFolder.CreateFileAsync("SomeFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting)
        Await Windows.Storage.FileIO.WriteTextAsync(file, "aaaa")
        Dim fileRef = RandomAccessStreamReference.CreateFromFile(file)
        emailMessage.Attachments.Add(New EmailAttachment(file.Name, fileRef))
        Await EmailManager.ShowComposeNewEmailAsync(emailMessage)

To, subject and body show fine in Outlook, but the attachment is missing: Outlook screenshot

like image 733
tcctest Avatar asked Oct 10 '15 11:10

tcctest


1 Answers

This is still an issue in 2019, but I have found a workaround for my project. I simply assemble an *.msg file with recipients, subject, body, attachments etc. and save it to the apps local cache folder. It can then be launched using Launcher.LaunchFileAsync

As *.msg files are associated with outlook, it will most likely be the default app to open this kind of file. You can create such a file using MsgKit

I have prepared a demo project at: https://github.com/Moolt/UniversialWindowsPlatform.LaunchOutlook

like image 160
Moolt Avatar answered Oct 25 '22 00:10

Moolt