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:[email protected]?subject=MySubject&body=MyContent"));
With this code line I can send an email, but I want to send a message with attachment.
Launch the compose email dialogCreate a new EmailMessage object and set the data that you want to be pre-populated in the compose email dialog. Call ShowComposeNewEmailAsync to show the dialog. Attachments that you add to an email by using the EmailAttachment class will appear only in the Mail app.
The main difference between Outlook and the Mail app is the target audience. The bundled app with Windows is meant to cater to consumers and those who check their emails on a daily basis. Outlook on-the-other-hand is for business and professionals who rely on email.
Step 1: Go to Visual Studio 2015 update 3. Open Visual Studio New-->New project -->select Visual C# --->select Windows -->Universal -->select Blank Windows Universal App and give your app; a name (ex: sample). Step 2: Next step is to select the target version of Windows 10 SDK (Windows 10 Build 10240).
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:
/// <summary>
/// Initiates sending an e-mail over the default e-mail application by
/// opening a mailto URL with the given data.
/// </summary>
public static async void SendEmailOverMailTo(string recipient, string cc,
string bcc, string subject, string body)
{
if (String.IsNullOrEmpty(recipient))
{
throw new ArgumentException("recipient must not be null or emtpy");
}
if (String.IsNullOrEmpty(subject))
{
throw new ArgumentException("subject must not be null or emtpy");
}
if (String.IsNullOrEmpty(body))
{
throw new ArgumentException("body must not be null or emtpy");
}
// Encode subject and body of the email so that it at least largely
// corresponds to the mailto protocol (that expects a percent encoding
// for certain special characters)
string encodedSubject = WebUtility.UrlEncode(subject).Replace("+", " ");
string encodedBody = WebUtility.UrlEncode(body).Replace("+", " ");
// Create a mailto URI
Uri mailtoUri = new Uri("mailto:" + recipient + "?subject=" +
encodedSubject +
(String.IsNullOrEmpty(cc) == false ? "&cc=" + cc : null) +
(String.IsNullOrEmpty(bcc) == false ? "&bcc=" + bcc : null) +
"&body=" + encodedBody);
// Execute the default application for the mailto protocol
await Launcher.LaunchUriAsync(mailtoUri);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With