edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
Zalak Patel
Published

Mail Communication with Odinub

Let's do mail communication using Python and get the information of your Odinub in your mailbox.

IntermediateProtip741
Mail Communication with Odinub

Things used in this project

Hardware components

Odinub
Odinub
×1

Story

Read more

Code

mail.py

Python
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
 
fromaddr = "[email protected]"         #write the sender e-mail address
toaddr = "[email protected]"        #write the receiver e-mail address
 
msg = MIMEMultipart()
 
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE EMAIL"     #write the subject you want to send 
 
body = "TEXT YOU WANT TO SEND"                #write the body of e-mail you want to send
 
msg.attach(MIMEText(body, 'plain'))
 
filename = "image_name.jpg"                          #write the image name you want to send
attachment = open("Path_of_image\image_name.jpg", "rb")     #write path of image you want to send
 
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
 
msg.attach(part)
 
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "password_of_sender_mail")      #write password of sender mail
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

print(β€œMail Sent”)

Credits

Zalak Patel
4 projects β€’ 3 followers

Comments