locked
How to send email in windows metro apps programmatically? RRS feed

  • Question

  • Hi,

    I need to send email from windows 8 apps programatically using C# code.

    Wednesday, January 2, 2013 11:01 AM

Answers

  • Hi,

    You have three ways:

    1. Use the Share charm and let user send the mail.
    2. Set up a small web service that receives a POST requests and sends mail automatically. This can be done in PHP in three lines of code, I've used it for error reporting in my WP7 app.
    3. Use Launcher for it:
    var mailto = new Uri("mailto:?to=a@a.com&subject=Hello&body=Text goes here"); 
    await Windows.System.Launcher.LaunchUriAsync(mailto);

    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 5:42 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 7:47 AM
    Wednesday, January 2, 2013 11:23 AM
  • Hi Toni,

    Above your code is i already tried but it will be redirected into web browser.

    This might be because your machine don't have default mail client preferred. Rest of the options is always recommended.

    @ Toni - Sorry about my previous post which says the same you posted, i missed your post as i didn't refresh my browser.


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Edited by Ramprasath R Wednesday, January 2, 2013 12:11 PM
    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 5:42 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 7:47 AM
    Wednesday, January 2, 2013 12:11 PM

All replies

  • Hi,

    You have three ways:

    1. Use the Share charm and let user send the mail.
    2. Set up a small web service that receives a POST requests and sends mail automatically. This can be done in PHP in three lines of code, I've used it for error reporting in my WP7 app.
    3. Use Launcher for it:
    var mailto = new Uri("mailto:?to=a@a.com&subject=Hello&body=Text goes here"); 
    await Windows.System.Launcher.LaunchUriAsync(mailto);

    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 5:42 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 7:47 AM
    Wednesday, January 2, 2013 11:23 AM
  • Two options could be suggested :

    1. If composed the body of email and you want your app user to manually send the email, then Sharing is good one. Check this out : http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh973055.aspx
    2. If you want emails to be sent non-interactively, you should create a web service and send email from there when you app calls it.

    Using Launcher might be an option to open the default mail client to send the email, but user interaction is needed here.


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Edited by Ramprasath R Wednesday, January 2, 2013 11:27 AM
    Wednesday, January 2, 2013 11:26 AM
  • Hi Toni,

    Above your code is i already tried but it will be redirected into web browser.

    Wednesday, January 2, 2013 11:54 AM
  • Hi Toni,

    Above your code is i already tried but it will be redirected into web browser.

    This might be because your machine don't have default mail client preferred. Rest of the options is always recommended.

    @ Toni - Sorry about my previous post which says the same you posted, i missed your post as i didn't refresh my browser.


    - Ram

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Edited by Ramprasath R Wednesday, January 2, 2013 12:11 PM
    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 5:42 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 7:47 AM
    Wednesday, January 2, 2013 12:11 PM
  • Hey,

    Did you get any solution ?

    I am also looking for the same.


    Regards, Govind

    Friday, February 28, 2014 5:44 PM