PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Send email

← All stacks

Theory

89/268

Send email

Send email 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.

Send email — output: Marks then Asha scored 90. Real email.message object. SMTP send needs login — don’t put passwords in code.

Exam tip

Parts of an email + never commit passwords.

Example

# Send email
from email.message import EmailMessage
m = EmailMessage()
m["From"] = "teacher@school.in"
m["To"] = "asha@school.in"
m["Subject"] = "Marks"
m.set_content("Asha scored 90")
print(m["Subject"])
print(m.get_content().strip())

Send email — output: Marks then Asha scored 90. Real email.message object. SMTP send needs login — don’t put passwords in code.

Short notes

  • From / To / Subject / body
  • smtp or Gmail API
  • TrapPassword in code.

Questions

1

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

2

What does the example print, and why?

3

What mistake do freshers make with Send email?

Previous← Regular Expressions in PythonNextDate →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.