The plain text version of an email is getting encoded to base64.
It only gets encoded to base64 Content-Transfer-Encoding: base64
when it includes a text string longer than 256 characters. At 256 characters or less, no encoding is applied.
I'm checking the plain text using 'show original' in Gmail.
I've tried escaping special characters https://stackoverflow.com/a/9204218/1027723 but it makes no difference.
So this email body is fine (max text string length = 256 characters):
You can ** unsubscribe from this newsletter (https://script.google.com/a/macros/website.co.uk/s/7iInODLb2Vu5mZyN07tvBzni1CK6Ez15SQfrFMhW3AWhc6RlrtnKFTeFt85Y9djYvBOuT3ZGlv/exec?token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=&token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=WQiOjM2OH0MWQi)
But add one more character to that long string and it gets encoded to base64:
You can ** unsubscribe from this newsletter (https://script.google.com/a/macros/website.co.uk/s/7iInODLb2Vu5mZyN07tvBzni1CK6Ez15SQfrFMhW3AWhc6RlrtnKFTeFt85Y9djYvBOuT3ZGlv/exec?token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=&token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=WQiOjM2OH0MWQiM)
I'm sending using MailApp. To reproduce the error:
const recipient = ''; // enter email address
const subject = 'test plain text email';
const plaintext = `You can ** unsubscribe from this newsletter (https://script.google.com/a/macros/website.co.uk/s/7iInODLb2Vu5mZyN07tvBzni1CK6Ez15SQfrFMhW3AWhc6RlrtnKFTeFt85Y9djYvBOuT3ZGlv/exec?token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=&token=eyJuYW1lIjoiQWWsaXRpc3QgQ29udHMgIiwiaWQiOjM2OH0=WQiOjM2OH0MWQiM)`;
function sendEmail() {
MailApp.sendEmail(
recipient,
subject,
plaintext)
}
The resulting plain text email ('show original' in gmail):
The desired outcome is to send a plain text email including a string that exceeds 256 characters without it encoding to base64.
Questions
Does it matter that base64 encoding is applied to the plain text version?
Could it negatively impact spam filters?
Thoughts and links
- Would using Content-Transfer-Encoding: base64 for text and html email present any issues?
- Does the encoding happen to avoid lines that are longer than smtp is happy with? (see https://tools.wordtothewise.com/rfc/5321#page-63 # section 4.5.3.1.6)
- Base64 encoded plain text makes your mail 25% bigger than quoted printable.
- Focusing on accessible text/html is a better use of effort than lovingly crafting a text/plain alternative!