Email Automation
Sending mail via gmail
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_content = '''Hello, Mail is sent!!
'''
#The mail addresses and password
sender_address = 'sahil.6906@gmail.com'
sender_pass = ''
receiver_address = ''
#Setup the MIME
message = MIMEMultipart()
message['From'] = 'sahil.6906@gmail.com'
message['To'] = ''
message['Subject'] = 'Test mail' #The subject line
#The body and the attachments for the mail
message.attach(MIMEText(mail_content, 'plain'))
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587) #use gmail with port
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print("mail sent")Sending Mail via gmail with attachment
Sending one mail to multiple email ids in excel
Last updated
Was this helpful?