Hi, I have a problem with a script I made. I think it is because some characters change because I write the script in Belgium. So I know that sometimes I need to use a ; in place of ,.
So the problem is that my app says that a mail has been sent to the address but I don't receive any email.
OK, I have tested this script locally in a spreadsheet, I have assumed that A is a name, B is the email, and C is the password. This worked for me and sent an email (I substituted values/parameters for testing):
function getPassword() {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var email = e.parameter.email;
var rg = sh.getName() + "!" + sh.getDataRange().getA1Notation();
var sql = '"SELECT A,B,C WHERE B =\'' + email + '\'"';
var qry = '=iferror(query(' + rg + ',' + sql + '),"")';
var ts = ss.insertSheet();
var setQuery = ts.getRange(1,1).setFormula(qry);
var getResult = ts.getDataRange().getValues();
var getPWD = getResult[0][2];
ss.deleteSheet(ts);
MailApp.sendEmail(email,'here is your password',getPWD);
}
The two differences I can see are:
the qry syntax here: + sql + '),"")'; where you might be using + sql + ');"")'; for your locale (if you are not use en for your locale)
and
var getPWD = getResult[0][2];
to correctly return the password from the json array
While I have your attention, currently we are working to get your blocks and script operating successfully. Once achieved, you should consider protecting your users data and password with some form of encryption. (you have a legal obligation to do this under GDPR) Sending plain text passwords by email is not the best practice.
Hey TIMAI, thanks for your help. Unfortunately I am still not getting any email. But since you wrote that it is not a good idea to send an email address, I will look for a possibility to reset the password via an email with a link.
I'm sorry for bringing this topic up again, but I think I have found the solution.
There is some processing in the new MailApp system that prevents the receiptent from receiving the email, however for the sender, you will still see that you have sent the mail in your Gmail dashboard.
For now, for anyone who wants to send emails with Apps Script, use GmailApp instead.