在用户脚本中使用SmtpJS:不起作用,没有错误消息? [英] Using SmtpJS in a userscript: Doesn't work, no error messages?
问题描述
我正在尝试使用smtpjs通过用户脚本发送电子邮件,因为这似乎是最简单的方法.但是,这似乎比仅通过嵌入HTML页面中的javascript发送更为困难.使用此用户脚本(基于smtpjs网站的 ),我在控制台中没有看到错误,也没有发送电子邮件,这是框架问题还是我在这里缺少什么? (如果您建议在用户脚本内发送电子邮件的更简便方法,请随时分享)
I'm trying to send an email through a userscript using smtpjs because it seems the easiest approach. However it seems more difficult than just sending it by javascript that is embedded in a HTML page. 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? (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");
}
(我尝试使用gmailAPI(纯JS版本不支持发送电子邮件吗?)和emailjs框架,但用户脚本均未成功)
(I tried gmailAPI (pure JS version doesn't support sending emails?) and emailjs framework without success in userscripts)
推荐答案
如果您查看 smtpjs.com源代码,它会创建一个发布请求网址,然后将其附加到<link>
内部的文档中.这不适用于安全页面.
If you look at the smtpjs.com source, it creates a post request url, then appends it to the document inside of a <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)
}
};
您可以使用上面的大多数代码...保留send
函数,但将addScript
函数替换为 GM_xmlhttpRequest
将数据发布到其服务器.
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.
这篇关于在用户脚本中使用SmtpJS:不起作用,没有错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!