smtplib sendmail code example
Example 1: email authentication python
import smtplib
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login("your username", "your password")
server.sendmail(
"[email protected]",
"[email protected]",
"this message is from python")
server.quit()
Example 2: smtp in python
import smtplib
from email.message import EmailMessage
EmailAdd = "Email id"
Pass = "Email Password"
msg = EmailMessage()
msg['Subject'] = 'Subject of the Email'
msg['From'] = EmailAdd
msg['To'] = '[email protected]','[email protected]'
msg.set_content('Mail Body')
with smtplib.SMTP_SSL('smtp.gmail.com',465) as smtp:
smtp.login(EmailAdd,Pass)
smtp.send_message(msg)