Apps Script MailApp throwing error : Exception: Invalid email: [L<?> (line 11, file "Code")

2,146 views
Skip to first unread message

Mallikarjunagowda Gowdara

unread,
Feb 18, 2022, 3:17:17 AM2/18/22
to Google Apps Script Community

I am trying to send an email from app script by triggering a deployement. My code is as below:

function doGet(e) { 
   return SendMail(e); 

function doPost(e) { 
  return SendMail(e); 
function SendMail(e) { 
  var recipient = e.parameters.recipient; 
  var body = e.parameters.body; 
          MailApp.sendEmail({ 
              to: recipient, 
              subject: "Test Mail", 
              htmlBody: "Dear Sir/ Madam, <br> Test Code " +body+ , name: "Test App" 
  }); 
          return ContentService.createTextOutput(recipient) }
 


How ever its throwing an error : Exception: Invalid email: [L<?> (line 11, file "Code")

Kindly help me. I am properly passing the email Id. If I return the conterService,createTextOutput with recipient variable, it returns the proper email id.

Kindly help.

Braja Patnaik

unread,
Feb 18, 2022, 5:52:32 AM2/18/22
to Google Apps Script Community
Please use:
var recipient = e.parameters.recipient.toString();

URL Parameters are passed as objects. This needs to be converted to string before calling sendEmail(). 

Also, in this line: htmlBody: "Dear Sir/ Madam, <br> Test Code " +body+ , name: "Test App" , I think the name is not defined anywhere. Is that a typo?
Also, the body variable also should be converted to string once you get it from the url parameter
Reply all
Reply to author
Forward
0 new messages