title: Google Workspace email sending with Google Appscript is giving error. Message blocked Your message to has been blocked
body: <p>My script was working fine with normal Gmail account but is giving error with Google Workspace account.
  I have read somewhere that I need to use GmailApp in place of MailApp, I have already done that. It seems that mail is sent but after that it is blocked.</p>
  <p>I am getting the following error:</p>
  <blockquote>
  <p>Message blocked</p>
  <p>Your message to xxxxxxx has been blocked.
  See technical details below  for more information.</p>
  <p>LEARN MORE</p>
  </blockquote>
  <p>The script is as below:</p>
  <pre><code>function exportPartAsPDF(selectedRanges,shId,regNo) {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheets()[shId];
  var selectedRange = sheet.getRange(selectedRanges);
  var pdfNameValue = sheet.getRange(regNo).getValue();
  var pdfName = (pdfNameValue || &quot;export&quot;) + &quot;.pdf&quot;;
  try {
      var blob = _getAsBlob(spreadsheet.getUrl(), sheet, selectedRange);
      blob.setName(pdfName);
      _sendMail(blob);
  } catch (e) {
      console.log(e);
  }
  
  return;
  }
  
  function _getAsBlob(url, sheet, range) {
  var rangeParam = &quot;&quot;;
  var sheetParam = &quot;&quot;;
  if (range) {
      rangeParam =
          &quot;&amp;r1=&quot; +
          (range.getRow() - 1) +
          &quot;&amp;r2=&quot; +
          range.getLastRow() +
          &quot;&amp;c1=&quot; +
          (range.getColumn() - 1) +
          &quot;&amp;c2=&quot; +
          range.getLastColumn();
  }
  if (sheet) {
      sheetParam = &quot;&amp;gid=&quot; + sheet.getSheetId();
  }
  var exportUrl =
      url.replace(/\/edit.*$/, &quot;&quot;) +
      &quot;/export?exportFormat=pdf&amp;format=pdf&quot; +
      &quot;&amp;size=A4&quot; +                                //A3/A4/A5/B4/B5/letter/tabloid/legal/statement/executive/folio
      &quot;&amp;portrait=true&quot; +
      '&amp;scale=4' +
      &quot;&amp;fitw=true&quot; +
      &quot;&amp;top_margin=0.5&quot; +
      &quot;&amp;bottom_margin=0.5&quot; +
      &quot;&amp;left_margin=0.5&quot; +
      &quot;&amp;right_margin=0.5&quot; +
      &quot;&amp;gridlines=false&quot;  +              //true/false
      &quot;&amp;horizontal_alignment=CENTER&quot; + //LEFT/CENTER/RIGHT
      &quot;&amp;vertical_alignment=TOP&quot; +      //TOP/MIDDLE/BOTTOM
      &quot;&amp;sheetnames=false&amp;printtitle=false&quot; +
      &quot;&amp;pagenum=false&quot; +
      &quot;&amp;gridlines=false&quot; +
      &quot;&amp;fzr=FALSE&quot; +
      sheetParam +
      rangeParam;
  Logger.log(&quot;exportUrl=&quot; + exportUrl);
  var response = UrlFetchApp.fetch(exportUrl, {
      headers: {
          Authorization: &quot;Bearer &quot; + ScriptApp.getOAuthToken(),
      },
  });
  
  return response.getBlob();
  }
  
  function _sendMail(blob) {
  var toEmail = &quot;xxxxxx@gmail.com,xxxx@print.epsonconnect.com&quot;;
  var htmlBody = &quot;Payment Recieved&quot;;
  var subject = &quot;Reciept&quot;;
  
  var options = {
      attachments: blob,
      htmlBody: htmlBody,
  };
  GmailApp.sendEmail(toEmail, subject, &quot;html content only&quot;, options);
  }
  </code></pre>