0

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):

test email result - bad

The desired outcome: test email result - good

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

TopMarx
  • 77
  • 8
  • Please provide [mcve]. I tried it myself and I don't see the problem. – Cooper Aug 03 '23 at 22:50
  • Thank you @Cooper it worked for you? I'll edit the question to be clearer. – TopMarx Aug 04 '23 at 00:05
  • Now I just a url in the email. – Cooper Aug 04 '23 at 00:59
  • Hi @Cooper so I presume you are looking at the HTML version of the email and not the plain text version? What do you see if you select 'show original' and look at the message source? thanks – TopMarx Aug 04 '23 at 01:30
  • Nope I am looking at the plain text. I provided no html – Cooper Aug 04 '23 at 01:31
  • Ok where do you see the plain text email? – TopMarx Aug 04 '23 at 01:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254790/discussion-between-topmarx-and-cooper). – TopMarx Aug 04 '23 at 01:56
  • so I'm trying to get rid of the base64 encoding, gmail doesn't show the text version any more, afaik stackoverflow.com/questions/… so it's decoding the base64 encoding. The plain text version is in base64 encoding. To view text version of message, click on more and select ‘Show original’ – TopMarx Aug 04 '23 at 02:07
  • The email looks like plain text to me – Cooper Aug 04 '23 at 02:10
  • @Cooper have you checked to see there's no base64 encoding under 'show Original'? – TopMarx Aug 04 '23 at 02:16
  • Yeah I see the encoding there but I was just looking at the email and it looks like plain text to me. – Cooper Aug 04 '23 at 02:24
  • You can elminate the encoding by removing the `https:` from the beginning of the strings – Cooper Aug 04 '23 at 02:31
  • @Cooper by removing `https:` you are shortening the string length and that is why it works, not because `https:` affects the encoding. Remove the `https:` and keep the string length the same, and the problem remains – TopMarx Aug 04 '23 at 03:31
  • @TopMarx From `I notice your reply includes an htmlBody variable, but I create that separately so I'm not sure it's applicable. I didn't really understand what your code is doing. What is the benefit of enabling Gmail API? What are all the MIME version, mailData, boundaries, etc? I don't really understand it. Thank you`, I thought that my answer was not useful for your situation. In this case, I have to delete my answer. Because I don't want to confuse other users. I think that this is due to my poor skill. I deeply apologize for my poor skill again. – Tanaike Aug 04 '23 at 07:51
  • I added more characters to the front of the string. It's not the length. They just see the protocol and encode it. But without the protocol they don't – Cooper Aug 04 '23 at 13:25
  • I made a 300 character long random character string and they did not encode it – Cooper Aug 04 '23 at 13:28
  • @Cooper ok thank you, how strange, I did that test and it did encode! – TopMarx Aug 04 '23 at 13:34
  • I just tested again, I went to this site http://www.unit-conversion.info/texttools/random-string-generator/ generated a 300 character string, sent an email, and it encodes to base64. I also tested with a random string of 256 character length, and that didn't encode to base64 – TopMarx Aug 04 '23 at 13:39
  • I cannot confirm that. – Cooper Aug 04 '23 at 14:44
  • My content type is plain text in both original and email – Cooper Aug 04 '23 at 14:55
  • Cooper and Tanaike, thank you for your help, I've re-edited my question for clarity, I really appreciate your time looking into this – TopMarx Aug 04 '23 at 19:44

0 Answers0