title: How to tell if an email sent via Gmail REST API has bounced?
body: <p>I'm sending emails via Gmail API and would like to know when the messages bounce. How can I do this?</p>
  
  <p>As I understand it, bounced emails usually contain some sort of header indicating a bounce such as:</p>
  
  <pre><code>X-Failed-Recipients: zzzzzzzzzasdfasdfadfa@gmail.com
  </code></pre>
  
  <p>However, there doesn't seem to always be a header indicating what original messageID it was that bounced.</p>
  
  <p>I was thinking of the following plan, but there are so many holes that I think I must be approaching this wrong.</p>
  
  <ol>
  <li>Send email (to a failed email) via Gmail API ---> It goes through successfully</li>
  <li>Receive the email bounced email inbox</li>
  <li>Scan email for emails containing bounced headers</li>
  <li>Try to figure out which original email it was that bounced.</li>
  </ol>
  
  <p>Problems </p>
  
  <ul>
  <li>Gmail api returns Gmail Message ID, not the actual message ID</li>
  <li>Have to continuously monitor/poll inbox to see if there's bounced emails</li>
  <li>Is it even possible to search by existence of a header?</li>
  <li>Each email provider out there seems to have different bounce headers </li>
  <li>The headers might not indicate original Message ID</li>
  </ul>
  
  <p>A couple other ideas I had were to:</p>
  
  <ul>
  <li>Search for emails with the string "Undeliverable" in the subject?</li>
  <li>not use gmail rest api for sending as bounce tracking is not feasible. perhaps use SMTP api instead?</li>
  </ul>