Created
September 3, 2018 09:07
-
-
Save nuriozbey/8d1a258fb55f4bdc6a746602c6796ac0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import smtplib | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.text import MIMEText | |
| from email.mime.base import MIMEBase | |
| from email import encoders | |
| import glob | |
| def getimputs(): | |
| fromaddr = input("Enter Email Adress : ") | |
| if fromaddr == "": | |
| fromaddr = "sender@gmail.com" | |
| passwd = input("Enter password of "+fromaddr+" : ") | |
| if (passwd == ""): | |
| passwd = "**********" | |
| folderpath = input("Enter Folder Path : ") | |
| if (folderpath == ""): | |
| folderpath = "C:/123/s234me/new23232ted" | |
| toaddr = input("Enter target Email Adress : ") | |
| if toaddr =="": | |
| toaddr = "receiver@asdf.com.tr" | |
| return fromaddr , passwd, folderpath , toaddr | |
| def main(): | |
| fromaddr , passwd, folderpath , toaddr = getimputs() | |
| server = smtplib.SMTP('smtp.gmail.com', 587) | |
| server.starttls() | |
| server.login(fromaddr, passwd) | |
| for filepath in glob.glob(folderpath + '/*'): | |
| msg = MIMEMultipart() | |
| msg['From'] = fromaddr | |
| msg['To'] = toaddr | |
| print(filepath) | |
| attachment = open(filepath, "rb") | |
| filename = filepath.split("\\")[-1] | |
| print(filename) | |
| msg['Subject'] = filename | |
| body = filename | |
| msg.attach(MIMEText(body, 'plain')) | |
| part = MIMEBase('application', 'octet-stream') | |
| part.set_payload((attachment).read()) | |
| encoders.encode_base64(part) | |
| part.add_header('Content-Disposition', "attachment; filename= %s" % filename) | |
| msg.attach(part) | |
| text = msg.as_string() | |
| server.sendmail(fromaddr, toaddr, text) | |
| server.quit() | |
| if __name__ == '__main__': | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment