Why can I send gmail emails with python, but not outlook emails?

%3CLINGO-SUB%20id%3D%22lingo-sub-2116308%22%20slang%3D%22en-US%22%3EWhy%20can%20I%20send%20gmail%20emails%20with%20python%2C%20but%20not%20outlook%20emails%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2116308%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20send%20custom%20emails%20to%20a%20list%20of%20people%20from%20a%20csv%20file.%20I%20practiced%20it%20with%20gmail%20and%20everything%20worked%20just%20fine%2C%20but%20I%20cannot%20get%20it%20to%20work%20with%20outlook%3CA%20href%3D%22https%3A%2F%2Fprotigwelders.com%2Fbest-tig-welder-for-aluminum%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E.%3C%2FA%3E%20The%20code%20starts%20running%20but%20never%20finishes.%20Here's%20the%20code%3A%3C%2FP%3E%3CP%3Eimport%20csv%2C%20smtplib%2C%20ssl%3C%2FP%3E%3CP%3Emessage%20%3D%20%22%22%22Subject%3A%20Your%20company%3C%2FP%3E%3CP%3EHi%20%7Bname%7D%2C%20your%20company%20is%20%7Bcompany%7D%22%22%22%3CBR%20%2F%3Efrom_address%20%3D%20%22myemail%40email.com%22%3CBR%20%2F%3Epassword%20%3D%20input(%22Type%20your%20password%20and%20press%20enter%3A%20%22)%3C%2FP%3E%3CP%3Econtext%20%3D%20ssl.create_default_context()%3CBR%20%2F%3Ewith%20smtplib.SMTP_SSL(%22smtp-mail.outlook.com%22%2C%20465%2C%20context%3Dcontext)%20as%20server%3A%3CBR%20%2F%3Eserver.login(from_address%2C%20password)%3CBR%20%2F%3Ewith%20open(%22practice.csv%22)%20as%20file%3A%3CBR%20%2F%3Ereader%20%3D%20csv.reader(file)%3CBR%20%2F%3Enext(reader)%3CBR%20%2F%3Efor%20name%2C%20email%2C%20grade%20in%20reader%3A%3CBR%20%2F%3Eserver.sendmail(%3CBR%20%2F%3Efrom_address%2C%3CBR%20%2F%3Eemail%2C%3CBR%20%2F%3Emessage.format(name%3Dname%2Ccompany%3Dcompany)%2C%3CBR%20%2F%3E)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2116308%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOutlook%20for%20Windows%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I'm trying to send custom emails to a list of people from a csv file. I practiced it with gmail and everything worked just fine, but I cannot get it to work with outlook. The code starts running but never finishes. Here's the code:

import csv, smtplib, ssl

message = """Subject: Your company

Hi {name}, your company is {company}"""
from_address = "myemail@email.com"
password = input("Type your password and press enter: ")

context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp-mail.outlook.com", 465, context=context) as server:
server.login(from_address, password)
with open("practice.csv") as file:
reader = csv.reader(file)
next(reader)
for name, email, grade in reader:
server.sendmail(
from_address,
email,
message.format(name=name,company=company),
)

0 Replies