2
votes

I have the following working code to send an email based on the content of one cell. This cell contains the values of other cells to create the email.

The emails send to 2 recipients and it works fine. However, upon receiving the email, the text is wrapped after 74 characters.

Sample sheet replicates issue: https://docs.google.com/spreadsheets/d/1PDSHbrhxiJliTGNx2rlJRAJIrjITADVuGWqTuvpjrgw/edit?usp=sharing

How can i prevent the wrapping? I want the email to send as it appears in the 'body' cell:

=G2&char(10)&E9&char(10)&E10&char(10)&E11&char(10)&E12&char(10)&E13&char(10)&E14&char(10)&E15&char(10)&E16&char(10)&E17&char(10)&E18&char(10)&E19&char(10)&E20&char(10)&E21&char(10)&E22&char(10)&E23&char(10)&E24&char(10)&E25&char(10)&E26&char(10)&E27&char(10)&E28&char(10)&E29&char(10)&E30&char(10)&E31&char(10)

Send email function:

var EMAIL_SENT = 'EMAIL_SENT';

function SendEmailACC() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EmailACC");
  var startRow = 2; 
  var numRows = 2; 
  var dataRange = sheet.getRange(startRow, 1, numRows, 6); 
  var data = dataRange.getValues(); 
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var subject = row[2]; 
    var emailSent = row[5]; 
    var EMAIL_SENT = "Email Processed";
    var EMAIL_FAIL = "Email Not Sent";
    if (emailSent !== EMAIL_SENT) { 

      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);
      SpreadsheetApp.flush();

    }
  }
  Utilities.sleep(3000);// pause in the loop
  DeleteStatus();
}

How Sample email should look:


Good Morning,

The following claim may have had an incorrect or missing ACC number or was not submitted by the referrer at time of request.
The claim has since been amended or submitted for the release of $50. Updated details are as below.

Vendor ID: ABC123
Invoice number: ABCDE12345
Service Date: 11/10/2019
Patient: John Smith
Service Code(s): COD88
First supplied ACC Number: BTT123
Exam Type: Exam Abc

Amended or updated ACC Number: COD123

Please let me know if any further information is required.


How the email actually comes out:

Good Morning,

The following claim may have had an incorrect or missing ACC number or was 
not submitted by the referrer at time of request.
The claim has since been amended or submitted for the release of $50. 
Updated details are as below.

Vendor ID: G0A368
Invoice number: ABCDE12345
Service Date: 11/10/2019
Patient: John Smith
Service Code(s): COD88
First supplied ACC Number: BTT123
Exam Type: Exam Abc

Amended or updated ACC Number: COD123

Please let me know if any further information is required.

Any suggestions appreciated

1
In order to correctly replicate your situation, can you provide a sample Spreadsheet? Of course, please remove your personal information.Tanaike
Sample spreadsheet replicates issue: docs.google.com/spreadsheets/d/…Matthew Rowlands
Thank you for replying and providing the sample Spreadsheet. I could understand about your situation. So I proposed a modification point as an answer. Could you please confirm it? If that was not the result you want, I apologize.Tanaike

1 Answers

4
votes

How about this answer? Please think of this as jut one of several possible answers.

Pattern 1:

In this pattern, Class GmailApp is used.

MailApp.sendEmail(emailAddress, subject, message);
GmailApp.sendEmail(emailAddress, subject, message);

Pattern 2:

In this pattern, Gmail API is used. In this case, please enable Gmail API at Advanced Google services.

MailApp.sendEmail(emailAddress, subject, message);
var raw = Utilities.base64EncodeWebSafe("Subject: " + subject + "\r\n" + "To: " + emailAddress + "\r\n" + "Content-Type: text/plain; charset=UTF-8\r\n\r\n" + message + "\r\n\r\n");
Gmail.Users.Messages.send({raw: raw}, "me");
  • If the characters which are more than the version of Unicode 6.0 are included in the email, Gmail API is required to be used. Please be careful this. Ref

Note:

  • In my experience, also I had the same issue. At that time, the issue could be resolved by using Class GmailApp. But unfortunately, I couldn't find the detail explanation about this at the official document. I apologize for this.

References: