简体   繁体   中英

How to send e-mail from within a Win8 Metro App

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?

如果您想让用户明确发送电子邮件(而不是Twitter / Facebook),则可以使用共享超级按钮让用户发送文本,那么您应该使用mailto协议。

await Launcher.LaunchUri(new Uri("mailto://test@address.com?subject=email"));

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

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM