Using SmtpJS in usercript: doesn't work, no error messages?

I am trying to send an email using smtpjs because this is the easiest way. However, this seems more complicated than just submitting it using javascript embedded in the HTML page. Using this usercript ( based on smtpjs website ) I don’t get errors in the console and emails aren’t sent, is this a problem with the card or did I miss something? (if you offer an easier way to send emails in custom text, feel free to share them)

// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match * // @grant none // @require http://smtpjs.com/smtp.js // ==/UserScript== if (confirm("send mail?")) { Email.send(" FROM@gmail.com ", " TO@gmail.com ", "This is a subject", "this is the body", "smtp.gmail.com", "USER", "PW"); } 

(I tried gmailAPI (does the clean version of JS not support sending emails?) And the emailjs framework without success in user scripts)

+2
source share
1 answer

If you look at the source of smtpjs.com , it creates the URL of the mail request and then adds it to the document inside the <link> . This will not work on secure pages.

 /* SmtpJS.com */ Email = { send: function (t, e, o, n, d, r, c) { var a = Math.floor(1e6 * Math.random() + 1), m = "http://smtpjs.com/smtp.aspx?"; m += "From=" + t, m += "&to=" + e, m += "&Subject=" + encodeURIComponent(o), m += "&Body=" + encodeURIComponent(n), void 0 == d.token ? (m += "&Host=" + d, m += "&Username=" + r, m += "&Password=" + c, m += "&Action=Send") : (m += "&SecureToken=" + d.token, m += "&Action=SendFromStored"), m += "&cachebuster=" + a, Email.addScript(m) }, addScript: function (t) { var e = document.createElement("link"); e.setAttribute("rel", "stylesheet"), e.setAttribute("type", "text/xml"), e.setAttribute("href", t), document.body.appendChild(e) } }; 

You can use most of the above code ... save the send function, but replace the addScript function with GM_xmlhttpRequest to send data to their server.

+1
source

Source: https://habr.com/ru/post/1014068/


All Articles