GmailApp in Google Apps Script: Emoji Subjects Showing Garbled Characters After Oct 22 ✠ï¸Â

41 views
Skip to first unread message

sakthi dev

unread,
Oct 23, 2025, 5:10:59 AM (12 days ago) Oct 23
to Google Apps Script Community

Hi everyone,

I’m seeing a strange issue with GmailApp in Google Apps Script. Emails sent before Oct 22 with emoji subjects worked fine, but emails sent after Oct 22 show garbled characters.
but his subject beofre 21/10/2025 
🕒 ➕ Hours Added 👇 after 22/102025 🕒 ➕ Hours Added 👇

function sendDeletedSessionEmail() {
  var recipientEmail = "";
  // var subject = "Testing Email";
  var subject = `🕒 ➕ Hours Added 👇`;

  var htmlBody = `
  hello
  `;
  // let subject_encodeed = encodeSubject(subject);
  MailApp.sendEmail(recipientEmail, `=?UTF-8?B?${Utilities.base64Encode(Utilities.newBlob(subject).getBytes())}?=`, '', {
    htmlBody: htmlBody
  });
}

function encodeSubject(subject) {
  return `=?UTF-8?B?${Utilities.base64Encode(Utilities.newBlob(subject).getBytes())}?=`;
}


Kildere S Irineu

unread,
Oct 23, 2025, 7:19:32 AM (11 days ago) Oct 23
to google-apps-sc...@googlegroups.com

Hi!

This is an excellent and very sharp observation. You are correct, and this is not an error in your logic. This behavior change strongly indicates a positive update on Google's side for the Apps Script email services.

Here is a breakdown of what was happening, what likely changed, and how to fix it.

The "Why": A Tale of Two Encodings

The core of this issue is email subject line encoding, specifically for non-ASCII characters like emoji.

Before October 22, 2025:

The GmailApp and MailApp services in Apps Script had a known limitation: they did not always correctly handle UTF-8 characters (like emoji) in the subject line. They would often send the subject as-is, and many email clients would misinterpret the characters, leading to garbled text (mojibake).

To fix this, developers had to manually encode the subject using the standard email format (RFC 2047). Your code does exactly this:

JavaScript
// This manually creates a properly encoded subject
`=?UTF-8?B?${Utilities.base64Encode(Utilities.newBlob(subject).getBytes())}?=`

This code tells the email client: "The following text is in the UTF-8 character set, is Base64 encoded, and here is the encoded content." This was a necessary and clever workaround that forced email clients to display the emoji correctly.

On or After October 22, 2025:

Your observation strongly suggests that Google updated the GmailApp and MailApp services to be smarter. They now automatically detect when a subject contains non-ASCII characters and correctly encode it for you behind the scenes.

This is where the new problem comes from: Double Encoding.

  1. Your code takes the beautiful emoji subject: 🕒 ➕ Hours Added 👇

  2. You manually encode it into the correct format: =?UTF-8?B?8J+OiA...

  3. You then pass this already encoded string to the newly updated MailApp.sendEmail function.

  4. The new, smarter MailApp service sees your encoded string, thinks it's just regular text, and helpfully encodes it a second time!

The result is a garbled mess because the email client receives a double-encoded subject and doesn't know how to decode it properly.

The Solution: Let Apps Script Do the Work

The fix is now wonderfully simple: Stop doing the manual encoding and trust the Apps Script service to handle it for you.

Just pass the plain string with the emoji directly to the subject parameter.


Corrected Code

Here is the correct way to write your function now. I recommend using GmailApp as it's more powerful (allows for aliases, sending from drafts, etc.), but this fix works for MailApp as well.

Using GmailApp (Recommended)

This is cleaner and the preferred service. Note that the subject is just the plain string.

JavaScript
function sendDeletedSessionEmail_GmailApp() {
  var recipientEmail = "your_...@example.com"; // Please enter a recipient for testing
  
  // The subject is now just the plain string with emoji.

  var subject = "🕒 ➕ Hours Added 👇";

  var htmlBody = 
`
  <h1>Hello!</h1>
  <p>This is a test to show the emoji subject is working correctly.</p>
  `;

  // No more manual encoding needed!
  GmailApp.sendEmail(recipientEmail, subject, "", {
    htmlBody: htmlBody
  });
}

Using MailApp (Your Original Service)

This also works with the same fix.

JavaScript
function sendDeletedSessionEmail_MailApp() {
  var recipientEmail = "your_...@example.com"; // Please enter a recipient for testing
  
  // The subject is the plain string.

  var subject = "🕒 ➕ Hours Added 👇";

  var htmlBody = 
`
  <h1>Hello!</h1>
  <p>This is a test using MailApp.</p>
  `;

  // The second parameter is for the plain text body, the third is the subject.
  // We remove your manual encoding from the subject.
  MailApp.sendEmail({
    to: recipientEmail,
    subject: subject,
    htmlBody: htmlBody
  });
}

Summary and Best Practice

  1. Remove Manual Encoding: Delete your encodeSubject function and any code that manually constructs the =?UTF-8?B?...?= string.

  2. Send Plain Strings: Pass the subject line with your emoji directly to the GmailApp.sendEmail or MailApp.sendEmail function.

  3. Trust the Platform: This is a positive change from Google that simplifies code and makes it more reliable. You no longer need the workaround.

You were not doing anything wrong; in fact, you were correctly using the best-practice workaround for the old behavior. The platform simply evolved underneath you


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/aa4015c9-49f5-4cb2-b4a1-b68e70507918n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages