Gmail API — Python Technical Interview Questions & Answers

Gmail API

Gmail API

  • Gmail API sends mail with smtplib / email.message, or a Gmail API. You need host, port, login. Never hard-code passwords in source — use env vars.
  • Classroom: show the Message structure (From, To, Subject, body). Real send needs credentials; the example prints the message text so it always runs.
  • Output: three header lines. Gmail API sends the same fields with OAuth — not a password in code.

Technical Interview Tip: Parts of an email + never commit passwords.

Code Examples for Gmail API

Example

# Gmail API
print("From: teacher@school.in")
print("To: asha@school.in")
print("Subject: Marks")

Output: three header lines. Gmail API sends the same fields with OAuth — not a password in code.

How to Explain Gmail API to an Interviewer

Explain Gmail API as if you are teaching a junior — definition, then one tiny script.

From / To / Subject / body smtp or Gmail API

What does the example print, and why?

three header lines

What mistake do freshers make with Gmail API?

Password in code.