0

I am developing a Windows8 Metro App using c# xaml and I have to send the app link as an e-mail to someone using the share contract.

What I have tried is private void RegisterForShare() { DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();

        dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.ShareLinkHandler);
          }

     private void ShareLinkHandler(DataTransferManager sender, DataRequestedEventArgs e)         {

       DataRequest request = e.Request; 
       request.Data.Properties.Title = "Sharing My Link";
       request.Data.Properties.Description = "Add a link (URI) to share";

       var _Uri = new Uri("https://login.live.com/");
        Windows.System.Launcher.LaunchUriAsync(_Uri);
   }

And also,

        void App_QuerySubmitted(Windows.ApplicationModel.DataTransfer.DataTransferManager sender, Windows.ApplicationModel.DataTransfer.DataRequestedEventArgs args)
    {
        App.SettingsFlyout.Equals(args.Request, ApplicationExecutionState.Running);

    }

But it works in a way where the specified link just opens and not a feature where the email of the link could be sent to soemone.

Any suggestions or solutions please?

dmurali
  • 211
  • 1
  • 6
  • 14

3 Answers3

1

While you can use the share charm to let the user sent text if you want to the user to definitely send email (as opposed to Twitter / Facebook) then you should use the mailto protocol.

await Launcher.LaunchUri(new Uri("mailto://test@address.com?subject=email"));
Nigel Sampson
  • 10,549
  • 1
  • 28
  • 31
  • Thanks Nigel..! This already works. But is there any way to mail content-specific data? Say, any selected item from an itemDetailPage? – dmurali Oct 18 '13 at 08:18
  • You can add content to the email by appending &body=itemDetailGoesHere – Nigel Sampson Oct 18 '13 at 09:41
  • I guess you have misunderstood! I mean, when a user clicks an item and clicks 'share', that particular item should be mailed to him! Is this possiblE? – dmurali Oct 18 '13 at 09:46
  • What I have tried now is the following, but it does not work! `ListView items = new ListView(); if (items.SelectedItems.Count == 1) { var item = "Selected Item: " + items.SelectedItem; request.Data.Properties.Title = "Item Selection"; request.Data.SetText(item); } else { request.Data.Properties.Title = "Select an item to share!"; }` – dmurali Oct 18 '13 at 14:10
0

There's no built-in API for sending emails. Microsoft recommend to use share charm to send the email. Though if you want to send email via you need to go for commercial library called Mail.dll

Farhan Ghumra
  • 15,180
  • 6
  • 50
  • 115
  • I just modified the code a little `void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { AoO.SettingsFlyout.Equals(args.Request, ApplicationExecutionState.Running); }` and ` DataRequest request = e.Request; request.Data.SetUri(new Uri("http://"));` and it works fine..!! – dmurali Oct 17 '13 at 14:40
0

Try this

 var mailto = new Uri("mailto:?to=recipient@example.com&subject=Your subject&body=Your text");     
 await Windows.System.Launcher.LaunchUriAsync(mailto);    
Jorge Freitas
  • 790
  • 10
  • 18