-
Notifications
You must be signed in to change notification settings - Fork 1
/
Aemail.py
45 lines (32 loc) · 1.23 KB
/
Aemail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
def main():
email_user = input("what is your gmail address? \n ")
email_password = input("what is the password for that email address? \n ")
email_rcver = input("what email address do you want to send to? \n ")
subject = input("Subject of the email : \n ")
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_rcver
msg['Subject'] = subject
body = input("write down body of the email : \n ")
msg.attach(MIMEText(body, 'plain'))
filename = input("Enter filepath of the file you want to upload : \n ")
attachment = open(filename, 'rb')
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('content-disposition', "attachment; filename= "+filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, email_password)
server.sendmail(email_user, email_rcver, text)
server.quit()
print("Sent!")
if __name__ == "__main__":
main()