javascriptgoogle-apps-scriptgoogle-sheetsgmail

Google Apps Script MailApp change Sender Name


I want to change the sender name of my outgoing mails. My code looks like this:

var emailAddress = sheet.getRange("D").getValue();
    var name = sheet.getRange("E").getValue();
    var personalizedMessage = Utilities.formatString(message, name);

    if (emailAddress) {
      MailApp.sendEmail(emailAddress, subject, personalizedMessage, {name: "Orthoback"});
    }
  }

Which matches (in my opinion) to the google documentation of the class MailApp:

MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', {
    name: 'Automatic Emailer Script',
    attachments: [file.getAs(MimeType.PDF), blob]
});

Unfortunately, the sender name remains the same. It's still just the sender mail address. Any ideas how to fix this?

Thanks in advance!


Solution

  • Which matches (in my opinion) to the google documentation of the class MailApp:
    Regrettably this is a not correct.

    The variable name appears several times in the script:

    The sender name is NOT being changed because of the duplicated name variable.

    The solution is to change the variable name used in the Personalised message. For example:

    This will result in "Othoback" being displayed as the sender.


    Sample

    sender name