Reputation: 41
I am using Apps Script and Gmail API to send a reply to the first message of a thread. The code I have works fine for sending the reply, but I'm facing an issue with the paragraph structure in the email body.
Here is my code snippet:
var originalMessage = messages[0];
var recipientEmail = originalMessage.getTo();
var messageId = originalMessage.getHeader("Message-ID");
var data = [
"MIME-Version: 1.0\n",
`In-Reply-To: ${messageId}\n`,
`Subject: Re:${originalMessage.getSubject()}\n`,
`From: ${firstName} ${lastName} <${senderEmail}>\n`,
`To: ${recipientEmail}\n\n`,
emailBody,
].join("");
var draftReplyRequestBody = {
message: {
threadId: existingThreadId,
raw: Utilities.base64EncodeWebSafe(data),
}
};
var draftReplyResponse = Gmail.Users.Drafts.create(draftReplyRequestBody, "me");
var draftReplyId = draftReplyResponse.id;
var sendReplyParams = { id: draftReplyId };
Gmail.Users.Drafts.send(sendReplyParams, "me");
The issue I'm facing is that when the recipient receives the reply email, the paragraph structure is destroyed. Long paragraphs are being shown as shortened lines, which affects the readability of the email.
For example, the original paragraph:
"I know you are extremely busy, and there is a possibility my last email got buried. I would be happy to provide you with more details regarding my CV . Your opinion will be very helpful in deciding whether or not I have a chance to participate in your company. Regards"
Turns into shortened lines in the recipient's email:
"I know you are extremely busy, and there is a possibility my last
email got buried. I would be happy to provide you with more details
regarding my CV . Your opinion will be very
helpful in deciding whether or not I have a chance to participate in
your company.
Regards"
I should also add that the script reads the email body from another sheet cell which contains the reply email boxy text. In addition, I checked it and it is not a screen or display dimension or device screen problem and it is related to paragraph formatting of the received email body. It has been changed.
I want to preserve the paragraph structure in the reply email and ensure that long paragraphs are displayed as intended. Is there anything I need to do to achieve this using the Gmail API in Apps Script?
Any insights or suggestions would be greatly appreciated. Thank you in advance!
Upvotes: 0
Views: 220