title: Email rejected by the Gmail API because of To header
body: <p>I'm trying to send a simple email via the <strong>Gmail API</strong> that's failing because of the RFC822-compliant <code>To: undisclosed-recipients:;</code> header. Sending with a regular address in the To header works fine. The RFC822 message is created by PHPMailer and recovered using <code>preSend()</code> and <code>getSentMIMEMessage()</code>.</p>
  <p>What am I doing wrong?</p>
  <h2>The message</h2>
  <pre><code>Date: Tue, 21 Sep 2021 09:13:17 +0000
  From: Rec1 &lt;fictive1@gmail.com&gt;
  Cc: &quot;Rec2 (fictive2@gmail.com)&quot; &lt;fictive2@gmail.com&gt;
  Bcc: fictive3@gmail.com
  Message-ID: &lt;vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg@vps&gt;
  X-Mailer: PHPMailer 6.5.1 (https://github.com/PHPMailer/PHPMailer)
  MIME-Version: 1.0
  Content-Type: multipart/alternative;
   boundary=&quot;b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg&quot;
  Content-Transfer-Encoding: 8bit
  To: undisclosed-recipients:;
  Subject: test
  
  This is a multi-part message in MIME format.
  
  --b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg
  Content-Type: text/plain; charset=us-ascii
  
  body
  
  --b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg
  Content-Type: text/html; charset=us-ascii
  
  &lt;div dir=&quot;ltr&quot;&gt;body&lt;/div&gt;
  
  
  --b1_vysFE9wLykAQc73VcxjiTfjPaZQJ5ge7jXqWbNeg--
  </code></pre>
  <h2>The answer</h2>
  <pre><code>{
    &quot;error&quot;: {
      &quot;code&quot;: 400,
      &quot;message&quot;: &quot;Invalid To header&quot;,
      &quot;errors&quot;: [
        {
          &quot;message&quot;: &quot;Invalid To header&quot;,
          &quot;domain&quot;: &quot;global&quot;,
          &quot;reason&quot;: &quot;invalidArgument&quot;
        }
      ],
      &quot;status&quot;: &quot;INVALID_ARGUMENT&quot;
    }
  }
  </code></pre>