I needed to send a lot of emails. I didn’t want to deal with an email sending company like MailChimp. I knew Python had some libraries that handled SMTP. I thought I’d check it out to see if I can build a localized email server and just send emails from my PC.
import smtplib, ssl host = '' port = '' local_host = 'localhost' email= '' password = '' receivers = [''] # receivers must be defined as a List. Get over it. smtpObj = smtplib.SMTP_SSL(host, port) smtpObj.login(sender, password) message = """ From: From Peter Krysik <firstname.lastname@example.org> To: Peter Krysik <email@example.com> MIME-Version: 1.0 Content-type: text/html Subject: <p>This is the content of the email. It works with HTML and CSS.</p> <p><span style="float: left; width: 0.8em; font-size: 600%; font-family: algerian, courier; line-height: 80%;">S</span>ee?</p> """
smtpObj.sendmail(email, receivers, message) # send the email.
with smtplib.SMTP_SSL(host, port, context=context) as server: server.login(email, password) server.sendmail(email, receivers, message) # send the email 2: this works, too.