0

Problem: Whenever I send a plain text email using the official google api node package (googleapis), I get line breaks around sentences longer than around 70 characters.

var headersObj = {
  "To": toEmail,
  "Subject": subject,
  "From": fromEmail,
  "Content-Type": "text/plain; charset=UTF-8"
  //"Content-Transfer-Encoding": "quoted-printable"
}

for(var header in headersObj) {
  email += header += ": " + headersObj[header] + "\r\n";
}

email += "\r\n" + message;
gmail.users.messages.send({
  userId: 'me',
  auth: oauth2Client,
  resource: {
    raw: btoa(email).replace(/\+/g, '-').replace(/\//g, '_')
  }
}, function (err, response) {
  if(err) {
    reject(err);
  }else{
    resolve(response);
  }
});

I heard I needed to change "Content-Transfer-Encoding" but that only works on html emails. What about plain text emails? I've been searching for months for an answer. Any suggestions, ideas, or solutions?

enter image description here

Please notice any line longer than 70 characters automatically breaks. Why does this behavior happen and how to solve it?

js_gandalf
  • 881
  • 8
  • 18
  • You may check on this [SO thread](http://stackoverflow.com/a/28531705/5832311) that discussed [Content-Transfer-Encoding](https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html). It stated that the `quoted-printable` encoding is designed to handle this. It defines that lines will be no greater than 76 characters, and that line breaks will be represented using special characters. *Quoted Printable, because of the escaping and short lines, is much harder to read by a human than `7bit` or `8bit`, but it does support a much wider range of possible content.* – abielita Dec 10 '16 at 18:42
  • Great! Thank you for your quick response. So is it impossible to send a plain-text email with lines greater than 76 characters? – js_gandalf Dec 12 '16 at 00:45

0 Answers0