2017-02-08 2 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を試してみました(あなたが共有することを躊躇しないuserscript内の電子メールを送信する簡単な方法を提案している場合)(電子メールの送信をサポートしていない純粋なJS版?)とuserscriptsでの成功なしemailjs枠組みを)

答えて

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_xmlhttpRequestaddScript機能を置き換えることができます。

+0

この回答は最新です。 smtpjsの[新しいバージョン](https://smtpjs.com/smtp.js)がHTTPSエンドポイントに対して 'XMLHttpRequest'を使用しているようです。しかし、それはまだ私のために動作していないようです。 –

関連する問題