Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,468 members, 7,958,431 topics. Date: Wednesday, 25 September 2024 at 02:12 PM |
Nairaland Forum / Science/Technology / Programming / Python Script To Send Jpg Files To Your Friend Via Gmail (1054 Views)
How To Convert OST Files To PST Format Without Outlook? / Gmail, Youtube, Google Docs And Other Services Go Down Simultaneously / How Do I Convert My Jpg Files To Doc And Pdf. (2) (3) (4)
(1) (Reply)
Python Script To Send Jpg Files To Your Friend Via Gmail by classicdude1(m): 11:10pm On Dec 24, 2017 |
Below is a Python script to send jpg files via gmail. import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEBase from email import encoders import os """ extensions of files that we will send """ extension = "jpg" """ This function returns a tuple with the files located in the current directory """ files = os.listdir() #this program should be saved in the current directory where your files are. """ We check what files have our wished extension """ for file in files: if extension in file: user ="sending@gmail.com" recv ="receiving@gmail.com" subject = "Subject" message = MIMEMultipart() message["From"] = user message["To"] = recv message["Subject"]= subject body = "Files with ." + extension + "extension" message.attach(MIMEText(body,"plain") attachment = open(file,"rb" part = MIMEBase("application","octet-stream" part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header("Content-Disposition","attachment; filename= " + file) message.attach(part) text = message.as_string() server = smtplib.SMTP("smtp.gmail.com",587) server.starttls() server.login(user,"your gmail pasword" server.sendmail(user,recv,text) server.quit() else: pass This code was shared by Om Tav on a Facebook page. You may get an error at first due to Google trying to protect your Gmail account from unknown app trying to login in. Just check your email and follow the steps provided by Gmail. Then run the code again. Happy Pythonic Holiday and try to automate your task with Python |
Re: Python Script To Send Jpg Files To Your Friend Via Gmail by dafeyankee: 11:11pm On Dec 24, 2017 |
Where the snake? |
Re: Python Script To Send Jpg Files To Your Friend Via Gmail by classicdude1(m): 11:14pm On Dec 24, 2017 |
hehehehe.... no snakes but there are a bunch of codes. |
(1) (Reply)
Forex - Investment WordPress Theme At Cheaper Rate / Vanhack Talent Accelerator Africa (feb 2018) Apply Now! / Error When Opening The File In MS Project 2007 ?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11 |