warspyking warspyking - 10 months ago 69
Javascript Question

Sending email from Chrome extension

I do not want the user to have to perform or confirm any actions, as it would disrupt the general idea. In other words, mailto is out of the question.

Is it possible to send emails client-sided via JavaScript, from a Chrome extension, without disrupting the user’s experience or adding any JavaScript extension? If so how?

I get the feeling this is going to be impossible.

EDIT: I've learnt that there is a chrome.sockets.tcp API that may be useable, any idea how?

Why all the downvotes? It's not like I tried to ask a question you all must have hated, I just kinda wanted this information so I could use it in an extension...

Solution: very very hard, not worth the trouble (see best answer)

Xan Xan
Answer Source

Since I can't think of a close reason for this question, here's an answer..

To send an e-mail, a program needs to connect via TCP to an SMTP server and talk to it according to the SMTP protocol.

  1. It is not possible to send an e-mail directly using JavaScript / HTML5 APIs.

    A browser does not expose the capability to directly communicate with a TCP socket.

    While you can initiate a connection to any port in principle, the browser will "do the talking" and it does not "speak" SMTP. It can do HTTP, it can do WebSockets, but not the protocol you want.

  2. It's not possible to send an e-mail directly from a Chrome extension.

    While the Chrome extension APIs augment functionality offered by web APIs, they still don't offer you the chance to "do the talking" to a server.

  3. It is possible, but not easy, to send an e-mail directly from a Chrome app.

    Chrome Apps APIs are different from extensions, but more importantly they include raw access to TCP sockets, via chrome.sockets.tcp API.

    Note the words "raw access". You will have to implement your own mail client from scratch in JavaScript. This might be a starting point.

    Depending on what you want to achieve, a Chrome app can be an acceptable solution. Alternatively, if you need both extension and app APIs, you can create both and pass messages between them.

  4. Anything is possible with a Native Messaging host.

    Being basically a native application, you can do anything from a native host app. Chrome extension/app will then be able to call it with necessary data.

    However, this will limit your deployment options if you decide to publish the extension; you will have to worry about portability, and the native host cannot be uploaded to the Web Store; you would need a separate installer.

    And your messaging host will still need to implement your own SMTP client, though you have a much more broad choice of ready libraries for that.

For extra reading, here's Apps vs Extensions guide.

Please note that any follow-up questions would probably be outside the scope of your original question.