locked
How to use mailto with launchUriAsync

    Question

  • Hi,

    I've found other related questions on these forums but no complete examples of how to do this. I'm trying to send an email from within a Windows 8 app and have set up the following code:

    var uriToLaunch = "mailto:?to=myemail@gmail.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.";
    
    var uri = new Windows.Foundation.Uri(uriToLaunch);
    
    // Launch the URI.
    Windows.System.Launcher.launchUriAsync(uri).done(
    function (success) {
        if (success) {
            console.log("Worked");
        } else {
            console.log("Failed");
        }
    });

    But it doesn't work. I've tried various formats for the mailto call based on what I've found online. If I substitute var uriToLaunch = "http://www.bing.com"; at the start of the block, it works fine (calls up Bing.com on my browser).

    Can someone point me to what I'm doing wrong?

    Thanks, S

    Monday, November 12, 2012 4:36 PM

Answers

  • Hi,

    First, you can't send email with windows store app directly. Javascript "mailto:" doesn't send a email, and just open your default email.

    If you want to send email, you could write a webservice to handle that.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:08 AM
    Tuesday, November 13, 2012 6:11 AM
  • for your first question. this line of code is wrong:

    var uriToLaunch = "mailto:?to=myemail@gmail.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.";

    it should be:

    var uriToLaunch = "mailto:myemail@gmail.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.";

    and i am not sure about the body parameter is supported.

    what about the sharing; you can change the message to "there is nothing to share right now" by attaching a event handler on each page but in that eventhandler provide just no data. So if you leave it empty it will be enough to get that message


     


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    • Edited by Dave SmitsMVP Tuesday, November 13, 2012 3:21 PM
    • Marked as answer by Song Tian Friday, November 16, 2012 9:08 AM
    Tuesday, November 13, 2012 3:21 PM

All replies

  • Quick follow up. I gave up on this and added support for the Share charm.

    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    
    dataTransferManager.addEventListener("datarequested", dataRequested);

    And I have a function called dataRequested to handle this and output text like in the text example. Only thing is I'm using a multi-page navigation app and the sharing on other pages now says: This App Can't Share. How can I change this message without adding sharing support to the other pages?

    Thanks, S

    Monday, November 12, 2012 8:22 PM
  • Hi,

    First, you can't send email with windows store app directly. Javascript "mailto:" doesn't send a email, and just open your default email.

    If you want to send email, you could write a webservice to handle that.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:08 AM
    Tuesday, November 13, 2012 6:11 AM
  • for your first question. this line of code is wrong:

    var uriToLaunch = "mailto:?to=myemail@gmail.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.";

    it should be:

    var uriToLaunch = "mailto:myemail@gmail.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.";

    and i am not sure about the body parameter is supported.

    what about the sharing; you can change the message to "there is nothing to share right now" by attaching a event handler on each page but in that eventhandler provide just no data. So if you leave it empty it will be enough to get that message


     


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    • Edited by Dave SmitsMVP Tuesday, November 13, 2012 3:21 PM
    • Marked as answer by Song Tian Friday, November 16, 2012 9:08 AM
    Tuesday, November 13, 2012 3:21 PM
  • Is there any way to transfer data with LaunchUriAsync method. I want to launch another app using Protocol activation and want to pass some data so that it can be used at receiving end.
    Wednesday, January 02, 2013 11:19 AM
  • Hi,

    If you have further issue but different than the original one in this thread, please open a new question. Thanks for your cooperation.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 03, 2013 1:31 AM
  • Can anyone figure out why there are not client email APIs in metro? WP8 and .net has them.
    Wednesday, February 06, 2013 2:19 AM