A
A
---
### 🧰 Requirements
* Python 3.x
* `smtplib` and `email` modules (built-in)
* Gmail account with **App Password** (required if 2FA is enabled)
---
* Visit: [https://myaccount.google.com/apppasswords](https://myaccount.google.com/
apppasswords)
* Choose "Mail" and "This device"
* Generate and copy the 16-character App Password
---
```python
import smtplib
from email.message import EmailMessage
import os
```
---
```python
EMAIL_ADDRESS = "[email protected]"
EMAIL_PASSWORD = "your_app_password"
recipients = [
"[email protected]",
"[email protected]",
"[email protected]",
]
```
```python
subject = "Exploring Opportunities – Backend Software Engineer"
body = """
I wanted to reach out to discuss potentially working together.
I’m a Backend software engineer working in LendingKart and currently seeking new
opportunities.
PFA my resume for your reference
LinkedIn: https://www.linkedin.com/in/ashish-singh-39127b288
---
```python
for recipient in recipients:
try:
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = EMAIL_ADDRESS
msg['To'] = recipient
msg.set_content(body)
# Add attachment
with open(resume_file, 'rb') as f:
file_data = f.read()
msg.add_attachment(file_data, maintype='application', subtype='pdf',
filename=os.path.basename(resume_file))
# Send
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
except Exception as e:
print(f"Failed to send to {recipient}: {e}")
```
---
| Error | Meaning
| Fix |
| ---------------------------------------------- |
--------------------------------------- |
--------------------------------------------------------------------- |
| `535 5.7.8 Username and Password not accepted` | Wrong password or App Password
not used | Use [App Password](https://support.google.com/mail/?p=BadCredentials) |
| `ConnectionRefusedError` | Gmail blocking login
| Use port `465` with `SMTP_SSL` |
---
* Keep a `.txt` or `.csv` file for recipient emails and load them dynamically
* Add a sleep (`time.sleep(1)`) to avoid hitting Gmail rate limits
---