Using selenium I have a code that determines if an item is 'in stock' or 'out of stock'. The code can detect once an 'out of stock' item becomes 'in stock'. Using smtplib, I'd like an email to be sent from the following email address:
[email protected] password: 1234
to:
notifying the individual once an item is 'in stock'.
What would a complete python code for this look like?.
CodePudding user response:
You can try something like :
import smtplib, ssl
from email.mime.text import MIMEText
port = 587 # For starttls
smtp_server = "smtp.office365.com"
sender_email = "the_sender_email_address" # [email protected]
password = "the_sender_email_address_password" # 1234
receiver_email = "the_receiver_email_address" # [email protected]
message = MIMEText("Hurry up.. Item in Stock Again") # Your message
message['Subject'] = "Item in Stock Again" # Email Subject
message['From'] = sender_email
message['To'] = receiver_email
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.as_string())