Real-World Scenario: Bulk Personalisation
Why Personalise Emails?
Imagine you’re sending updates to multiple users — wouldn’t it feel better if each message used their name and felt personal?
With Python, you can do that easily using a loop and a contact list.
Example: Sending Customised Emails in Bulk
contacts = [
{"email": "alice@example.com", "name": "Alice"},
{"email": "bob@example.com", "name": "Bob"}
]
for person in contacts:
msg["To"] = person["email"]
msg.set_content(f"""
Hi {person['name']},
Here is your personalised update for this week.
Regards,
Automation Bot
""")
server.send_message(msg)
print(f"Sent email to {person['name']}")
How It Works:
-
contacts: A list of dictionaries, each holding a user’s email and name. -
for person in contacts:: Loops through each contact. -
person["name"]andperson["email"]: Inject each user’s info into the email body and address. -
msg.set_content(): Adds a custom message for each person. -
server.send_message(msg): Sends the email. -
print(): Confirms the message was sent.
Why This Is Powerful:
-
Saves time — no need to write separate emails
-
Adds a personal touch — improves engagement
-
Scales easily — works for 2 or 200+ recipients
