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