Is it possible to send an email to a specific recipient through Share Contract?

﹥>﹥吖頭↗ 提交于 2019-12-11 06:28:46

问题


I'm trying to send an email from a Metro application (js or c#, doesn't matter) Is Share Contract the way to go? As far as I can tell you can't specify the email's recipient through the Share contract.


回答1:


You are correct. There is no way. You could try constructing a mailto Uri and launching it




回答2:


This is correct. The share contract is also available for other apps, i.e. Tweetro, which do not use an email address, therefore the user must type in an email address per hand. A mailto Uri does not work, it must be a valid Uri, otherwise it will not be displayed. See http://msdn.microsoft.com/en-US/library/windows/apps/hh465261 for all options you can set up for sharing via charms.




回答3:


Use the EmailManager.ShowComposeNewEmailAsync API if you're on Windows 10. It uses the mailto: protocol underneath.




回答4:


You can use a Uri scheme to open an app, but you need to use LaunchUriAsync. Also, with LauncherOptions set, if the user doesn't have the app installed Windows will bring them to the Store.

For example, here is my approach that only opens the mail app to side of the screen (I use it for error reporting), or if they have Outlook installed it will use it instead:

private async Task<bool> ReportErrorMessage(string detailedErrorMessage)
{
    var uri = new Uri(string.Format("mailto:email.address@domain.com?subject=Error Report&body={0}", detailedErrorMessage), UriKind.Absolute);

    var options = new Windows.System.LauncherOptions
    {
        DisplayApplicationPicker = true,
        DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseLess,
        PreferredApplicationPackageFamilyName = "microsoft.windowscommunicationsapps_8wekyb3d8bbwe",
        PreferredApplicationDisplayName = "Mail"
    };

    return await Windows.System.Launcher.LaunchUriAsync(uri, options);
}

In the case of an email uri, the app is installed already, so it should work equally for every user. Additionally, if you know the FamilyPackageName you can set the preferred app to use.

Find more information about using the uri launcher here.



来源:https://stackoverflow.com/questions/10579040/is-it-possible-to-send-an-email-to-a-specific-recipient-through-share-contract

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!