2017-02-08 13 views
2

가장 쉬운 접근 방법 인 것처럼 smtpjs를 사용하여 userscript를 통해 전자 메일을 보내려고합니다. 그러나 HTML 페이지에 포함 된 javascript로 보내는 것보다 더 어려워 보입니다. 이 userscript (based on the smtpjs website)를 사용하면 콘솔에 아무런 오류가 없으며 전자 메일도 전송되지 않습니다. 이것이 프레임 워크의 문제입니까 아니면 여기에 뭔가 빠졌습니까? 사용자 스크립트에서 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_xmlhttpRequest으로 addScript 기능을 대체 할 수있다.

+0

이 답변은 오래되었습니다. smtpjs의 [최신 버전] (https://smtpjs.com/smtp.js)이 HTTPS 끝점에 XMLHttpRequest를 사용합니다. 그러나, 그것은 여전히 ​​나를 위해 작동하지 않는 것 같습니다. –