Is it possible to send an email message in a Windows Universal App for Windows 8.1 and Windows Phone 8.1?
await Launcher.LaunchUriAsync(new Uri("mailto:abc@abc.com?subject=MySubject&body=MyContent"));
With this code line I can send an email, but I want to send a message with attachment.
To send emails with attachment You would be needed to use the
EmailMessage
andEmailManager
class.1. EmailMessage:
The EmailMessage class defines the actual email that will be sent. You can specify the recipients (To , CC , BC) , Subject and the Body of the email .
2. EmailManager:
The EmailManager class is defined in the Windows.ApplicationModel.Email namespace . The EmailManager class provides a static method ShowComposeNewEmailAsync which accepts the EmailMessage as argument . The ShowComposeNewEmailAsync will launch the Compose email Screen with the EmailMessage which allows the users to send an email message.
You can find more reference here windows-phone-8-1-and-windows-runtime-apps-how-to-2-send-emails-with-attachment-in-wp-8-1
Since Microsoft missed to add EmailMessage and EmailManager to the Windows Store Apps libraries it seems as if there are only two unsatisfactory solutions: You could use sharing or initiate email sending via the mailto protocol. Here is how I did it:
On this page: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871373.aspx
Microsoft supplies a example how to share with your application. Download the source example app: http://go.microsoft.com/fwlink/p/?linkid=231511
Open the solution and add a file: test.txt to the project root.
Then open ShareFiles.xaml.cs and replace the class with:
Might not be the best code, but it helped me :)
Windows Phone 8.1
You could use the following to send email with attachment:
Windows 8.1
On Windows 8.1, unfortunately, there is no way to send email with attachment. The mailto protocol is all you have and it doesn't not officially supports attachment. However, you can add attachment as the following:
or
But it is up to the client to decide whether it will handle the attachment or not. See this thread for more detail https://msdn.microsoft.com/en-us/library/aa767737(v=vs.85).aspx