MailApp.sendEmail doesn"t work

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.

Script

I hope someone can help me.

Many thanks in advance,
Steph

image

You don't need all those extra quotes...

{MailApp.sendMail(email,'here is your password',getPWD);}

should work. Also have a look at your syntax for the sql and qry variables.

ref

Also in your blocks

image

Do you have another parameter in your global URL? If not &func= should be ?func=

1 Like

This is the whole script...

OK, your global url has the spreadsheet details. You appear to be missing a & before the 1SH=

image

You do not appear to be switching screens correctly, this can lead to memory issues and app crashes.


blocks (1)

Hey Timai2,

This is what I get, but I don't receive any mail.

So, I think the problem is in one of this parts or in both...

send block send script

Thanks for your help!

I made the correction as you said...

Correction

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.

1 Like

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.

Many thanks for your help!

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.