├── .gitattributes ├── .gitignore ├── README.md └── send_email.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Email 2 | Simple Example of SMTP Protocol for Emailing 3 | 4 | In order to use replace the credentials passed as variables at the top. 5 | email_user = 'your_email' 6 | email_password = 'your_password' 7 | email_send = 'recipient_email' 8 | 9 | Set the filename variable to the filename of the attachment to be sent with email. 10 | filename='filename' 11 | -------------------------------------------------------------------------------- /send_email.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | from email.mime.text import MIMEText 3 | from email.mime.multipart import MIMEMultipart 4 | from email.mime.base import MIMEBase 5 | from email import encoders 6 | 7 | email_user = 'your_email' 8 | email_password = 'your_password' 9 | email_send = 'recipient_email' 10 | 11 | subject = 'subject' 12 | 13 | msg = MIMEMultipart() 14 | msg['From'] = email_user 15 | msg['To'] = email_send 16 | msg['Subject'] = subject 17 | 18 | body = 'Hi there, sending this email from Python!' 19 | msg.attach(MIMEText(body,'plain')) 20 | 21 | filename='filename' 22 | attachment =open(filename,'rb') 23 | 24 | part = MIMEBase('application','octet-stream') 25 | part.set_payload((attachment).read()) 26 | encoders.encode_base64(part) 27 | part.add_header('Content-Disposition',"attachment; filename= "+filename) 28 | 29 | msg.attach(part) 30 | text = msg.as_string() 31 | server = smtplib.SMTP('smtp.gmail.com',587) 32 | server.starttls() 33 | server.login(email_user,email_password) 34 | 35 | 36 | server.sendmail(email_user,email_send,text) 37 | server.quit() 38 | --------------------------------------------------------------------------------