Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Zalak Patel
Published

Mail Communication with Odinub

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

IntermediateProtip577
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 = "sender@gmail.com"         #write the sender e-mail address
toaddr = "recevier@domain.com"        #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
Contact

Comments

Please log in or sign up to comment.