2017-02-08 72 views
2

我想通過使用smtpjs的userscript發送電子郵件,因爲它似乎是最簡單的方法。然而,這似乎比通過嵌入HTML頁面的JavaScript發送更難。使用這個腳本(based on the smtpjs website)我沒有在控制檯中發生錯誤,沒有發送電子郵件,這是一個框架問題還是我在這裏丟失了什麼? (如果你的建議發送userscript內的郵件不要猶豫,分享更簡單的方法)在用戶腳本中使用SmtpJS:不起作用,沒有錯誤信息?

// ==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("[email protected]", 
        "[email protected]", 
        "This is a subject", 
        "this is the body", 
        "smtp.gmail.com", 
        "USER", 
        "PW"); 
    } 

(我試過gmailAPI(純JS版不支持發送電子郵件?)和emailjs框架沒有userscripts成功)

回答

1

如果您查看smtpjs.com source,它會創建一個發佈請求url,然後將其附加到<link>的文檔中。這在安全頁面上不起作用。

/* 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功能,但有GM_xmlhttpRequest更換addScript功能把數據上傳到他們的服務器。

+0

此答案已過期。似乎smtpjs的[新版本](https://smtpjs.com/smtp.js)使用'XMLHttpRequest'到HTTPS端點。但是,它似乎仍然不適合我。 –

相關問題