₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,110 members, 8,420,406 topics. Date: Thursday, 04 June 2026 at 06:39 PM

Toggle theme

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

Nairaland ForumScience/TechnologyProgrammingPython Script To Send Jpg Files To Your Friend Via Gmail (1127 Views)

1 Reply

Python Script To Send Jpg Files To Your Friend Via Gmail by classicdude1(op): 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(op): 11:14pm On Dec 24, 2017
hehehehe.... no snakes but there are a bunch of codes.
1 Reply

How To Convert OST Files To PST Format Without Outlook?Please Help: I'm At The Verge Of Losing My Final Yr Project Files To RansomwareHow Do I Convert My Jpg Files To Doc And Pdf.234

Is It Possible To Clone Up To 5 Simcards Into One Simcard And How ?Java Programming Language Methods And Object Need ExplanationProgrammers Needed In Ilorin