locked
SMTP library for Windows 8 (JS) or sending an email from Windows 8 using Javascript

    Question

  • Hi, 

    I am looking to send email from the application, so I was looking for an Javascript library for Windows 8.  To my surprise, I came up empty.  

    Is there a library for SMTP for javascript?

    I am not looking to launch a mail application from the app through mailto:// link.  On a desktop app, launching a mail app is fine.  On a Metro app, that will take the user out of the app completely.  That would be pretty disruptive to user experience.

    I found this thread in the forum, unfortunately, it does not tell us a library.

    http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/62a863f8-3efc-41fa-924d-3a33ad8f74f2

    thank you for any help.

    Wednesday, February 06, 2013 6:40 PM

Answers

  • C# is not needed for this. JavaScript apps can call the same Windows Runtime networking classes as C# can.

    There isn't any in-box mail API. The Sharing Contract can share data with email apps (among other options), or you can launch a "mailto:" URI as you mentioned in your original post.

    I would recommend one of these to leave the user in control of how and where the mail actually goes.

    If you need to connect directly to the server from within your app then you will need to implement that yourself. Many mail services have web-oriented API which you can use, but if you specifically need SMTP then you will need to implement it yourself. Take a look at the Windows.Networking.Sockets namespace and the Connecting with sockets documentation and samples.

    --Rob

    Monday, February 11, 2013 5:50 AM
    Owner

All replies

  • w-p,

    I don't believe you can access SMTP directly from JavaScript (see this related post), nor does it look like you can from WinJS. I would think your best bet is to create a WinMD library in C# (http://msdn.microsoft.com/en-us/library/windows/apps/br230301.aspx) to handle making the request for you. You can access the WinMD code from your JavaScript and send the email that way if desired.

    Also, if you don't need to target a specific email address, I would suggest taking a look at implementing a sharing contract so that you can just share the email content (or blank content) with the mail app. That won't change focus from your application but will still allow you to send the email.

    Wednesday, February 06, 2013 7:58 PM
  • hi got, thanks for the suggestions.  unfortunately, we are really looking for a way to do it inside the program itself.  Is C# the only way to go?
    • Edited by w-p Wednesday, February 06, 2013 10:57 PM
    Wednesday, February 06, 2013 10:55 PM
  • Seems like it unless there's some undocumented WinJS API I'm not aware of for handling those kind of requests.
    Wednesday, February 06, 2013 11:50 PM
  • C# is not needed for this. JavaScript apps can call the same Windows Runtime networking classes as C# can.

    There isn't any in-box mail API. The Sharing Contract can share data with email apps (among other options), or you can launch a "mailto:" URI as you mentioned in your original post.

    I would recommend one of these to leave the user in control of how and where the mail actually goes.

    If you need to connect directly to the server from within your app then you will need to implement that yourself. Many mail services have web-oriented API which you can use, but if you specifically need SMTP then you will need to implement it yourself. Take a look at the Windows.Networking.Sockets namespace and the Connecting with sockets documentation and samples.

    --Rob

    Monday, February 11, 2013 5:50 AM
    Owner
  • I used a third-party windows runtime component in my project, hope this could be helpful to you

    Send Email in JavaScript from Windows Store Apps - HTML5

    Sunday, July 14, 2013 2:55 AM