简体   繁体   English

在用户脚本中使用 SmtpJS:不起作用,没有错误消息?

[英]Using SmtpJS in a userscript: Doesn't work, no error messages?

I'm trying to send an email through a userscript using smtpjs because it seems the easiest approach.我正在尝试使用 smtpjs 通过用户脚本发送电子邮件,因为这似乎是最简单的方法。 However it seems more difficult than just sending it by javascript that is embedded in a HTML page.然而,它似乎比仅通过嵌入在 HTML 页面中的 javascript 发送它更困难。 Using this userscript ( based on the smtpjs website ) I get no error in the console and no email is sent, is this a framework issue or am I missing something here?使用此用户脚本(基于 smtpjs 网站)我在控制台中没有收到任何错误,也没有发送电子邮件,这是框架问题还是我在这里遗漏了什么? (if you suggest an easier way to send emails within a userscript don't hesitate to share) (如果您建议在用户脚本中发送电子邮件的更简单方法,请不要犹豫分享)

 // ==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 (pure JS version doesn't support sending emails?) and emailjs framework without success in userscripts) (我尝试了 gmailAPI(纯 JS 版本不支持发送电子邮件?)和 emailjs 框架,但在用户脚本中没有成功)

If you look at the smtpjs.com source , it creates a post request url, then appends it to the document inside of a <link> .如果您查看smtpjs.com 源代码,它会创建一个发布请求 url,然后将其附加到<link>内的文档中。 This won't 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 could use most of the above code... keep the send function, but replace the addScript function with a GM_xmlhttpRequest to post the data to their server.您可以使用上面的大部分代码...保留send功能,但将addScript功能替换为GM_xmlhttpRequest以将数据发布到他们的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM