Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,175,857 members, 7,895,719 topics. Date: Saturday, 20 July 2024 at 04:15 PM

Python Script To Send Jpg Files To Your Friend Via Gmail - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Script To Send Jpg Files To Your Friend Via Gmail (1041 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"wink)
attachment = open(file,"rb"wink
part = MIMEBase("application","octet-stream"wink
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"wink
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)

Laravel Crud Tutorial Series / Please Am In Need Of A Good Web Desinger And Programmer Based In Abuja. / USSD Developer Come In For A Job

(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. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.