r/tinycode • • Dec 25 '17

Python Script to send jpg files to your friend via Gmail

16 Upvotes

Hi Pythonic Redditors,

I came across this script to send jpg files via email and I thought it would be worthwhile to share it here.

I hope the lines of code are not too much to go against the rules.(If you can minimize it, I would appreciate your effort)

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" #sending gmail
        recv ="receiving@gmail.com" #receiving gmail
        subject = "Subject" #subject of email message
        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 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


r/tinycode • • Dec 24 '17

redditors DIY build system to replace GNU Make

Thumbnail
reddit.com
0 Upvotes

r/tinycode • • Dec 13 '17

One Pass Real Time Generational Mark and Sweep Garbage Collection

12 Upvotes

This erlang paper One Pass Real Time Generational Mark and Sweep Garbage Collection.

the algorithms they show are so concise. never seen anything like it.


r/tinycode • • Dec 05 '17

Build a Regex Engine in Less than 40 Lines of Code

Thumbnail
nickdrane.com
26 Upvotes

r/tinycode • • Nov 25 '17

Terrain rendering in less than 20 lines of code

Thumbnail
github.com
108 Upvotes

r/tinycode • • Nov 19 '17

A 3-INSTRUCTION FORTH FOR EMBEDDED SYSTEMS WORK

Thumbnail pygmy.utoh.org
21 Upvotes

r/tinycode • • Nov 06 '17

A concise URL shortener in Python

Thumbnail aguo.us
7 Upvotes

r/tinycode • • Nov 04 '17

SECD - a purely functional Lisp virtual machine in a couple of hundred lines of Python

Thumbnail
github.com
15 Upvotes

r/tinycode • • Nov 03 '17

stupid python tricks - literate programming in a handful

Thumbnail
thoughtstreams.io
8 Upvotes

r/tinycode • • Sep 22 '17

Ridiculously simple web page load balancer

Thumbnail
github.com
13 Upvotes

r/tinycode • • Sep 17 '17

A 256b coding seminar by TomCat/Abaddon at Function 2017

Thumbnail
youtu.be
17 Upvotes

r/tinycode • • Sep 16 '17

Magic of 256-byte x86 intros (presentation by Rrřola at Demobit 2017)

Thumbnail
youtu.be
30 Upvotes

r/tinycode • • Sep 12 '17

Classwrap – Tiny (320B) alternative to classnames. 20x faster & BEM style nested object support.

Thumbnail
github.com
5 Upvotes

r/tinycode • • Sep 11 '17

www a cross platform static web server in 100 lines with TLS support (acme/autocert)

Thumbnail
github.com
9 Upvotes

r/tinycode • • Sep 04 '17

Simple C++ reflection with CMake

Thumbnail
onqtam.com
6 Upvotes

r/tinycode • • Aug 11 '17

Steps to Reduce Code Size after Use of Strategy Pattern

Thumbnail
codingsight.com
4 Upvotes

r/tinycode • • Aug 10 '17

Print all the powers of two, up to 255 decimal digits, in 10 x86 instructions (x-post from /r/coding)

Thumbnail
github.com
33 Upvotes

r/tinycode • • Aug 06 '17

Co-dfns Live Stream: Compiler Design and Architecture [APL] [HIGH DENSITY]

Thumbnail
youtube.com
9 Upvotes

r/tinycode • • Jul 19 '17

My ShaderToy compo entry: Fireworks in less than 2 tweets

Thumbnail
shadertoy.com
26 Upvotes

r/tinycode • • Jul 14 '17

Moon - a 6kb UI library inspired by Vue

Thumbnail
github.com
17 Upvotes

r/tinycode • • Jul 14 '17

We love that software costs near nothing to mass produce but are therefore cursed with it having far more unnecessary parts than any other product

12 Upvotes

Most people see tinycode as screwing around. I see it as fixing a serious problem of dealing with the buildup of complexity.


r/tinycode • • Jul 13 '17

HyperApp - The 1 KB js lib for building front-end apps

Thumbnail hyperapp.glitch.me
21 Upvotes

r/tinycode • • Jul 10 '17

make? gmake? cmake? ninja? Minimal build system in 50 lines of /bin/sh

Thumbnail
notabug.org
20 Upvotes

r/tinycode • • Jul 10 '17

Skip cproto, autogenerate C function prototypes in a short shell pipeline of standard Unix tools

Thumbnail
notabug.org
5 Upvotes

r/tinycode • • Jul 10 '17

Precise Computation of CLR Object Size

Thumbnail
codingsight.com
1 Upvotes