2
votes

i am developing an metro application , where i have requirement :-

where i need to send some information from my app to end users through an email, i am generating the information or content for that email programatically through code.

Firstly thing i worked on is launching mailto app in my application in this way :-

using Windows.System;

//starts the default mail app with a subject, cc, bcc, and body
Launcher.LaunchUriAsync(new Uri("mailto:[email protected]?subject=Code Request&[email protected]&[email protected]&body=Hi!"));

Then i discovered that i cannot attach attachements to this mail app programatically through code if you are launching the mail app in this way.

Secondly, i worked on share contract where i can share content generated from my app to other apps (like mailto app also...)

and i was able to share my content successfully which means :-

using this i am able to attach a file(which i generated through code) to mailto app and if i specify the mail address and send it it works fine and delivered successfully )

But now i discovered that i cannot set the subject or body of the mail app to which i am sharing content , if i am using an share contract to share files.

so my doubt is :-

1) first of all , is there any way that i can set the subject or body of the mail app to which i am sharing content , if i am using an share contract to share files ??

2)Am i missing any other alternative / are there any other possible ways of sending email using metro app ??

3)if not , what is the workaround through which i can achieve my goal ( sending an email through which i can attach file programatically through code and have a body , subject set to it )

Thanks in advance.

2

2 Answers

0
votes

Unfortunatelly when using the share contract it's up to the share target to decide how the values you are setting are going to be used. You don't have any control over that. As you've noticed the built-in mail client doesn't use the other shared values when you're adding an attachment.

The only alternative I can think of is to send the mail directly from your code using SMTP. The downside is that there's no SmtpClient class in .NET for Windows Store apps and neither could I quickly find another .NET implementation of this functionality that you could use, so it seems you're on your own here. Also in this case you'd need the user to configure his SMTP server in your application.

Considering all that the best approach would probably be to take care of sending emails in the online component of your application, i.e. you create a service and host it somewhere. You then send the data for the mail from the app to your service and send the mail from there using the regular .NET SmtpClient.

2
votes

I have mostly good news for you:

  1. You can open the Win-RT mail app and prepare an email using mailto.

    Launcher.LaunchUriAsync(new Uri("mailto:[email]?subject=[subject]&body=[body]?"));

  2. See 1

  3. Best bet for this one is to upload the file somewhere and send the email with the link to the attachment in the body of the email

For other mail properties check out:

http://email.about.com/library/misc/blmailto_encoder.htm

Hope it helps!