-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto_email.py
More file actions
67 lines (47 loc) · 1.71 KB
/
Auto_email.py
File metadata and controls
67 lines (47 loc) · 1.71 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#default import for emailserver connection
import smtplib
#deafalt import for media
from email.mime.multipart import MIMEMultipart
message = MIMEMultipart("alternative")
#the email youll send it from
my_email = "passnowtutors@gmail.com"
password_key = "vtes shoz uoco rgpw"
#SMTP Server and port no for GMAIL.com
gmail_server = "smtp.gmail.com"
gmail_port = 587
#startting connection
my_server = smtplib.SMTP(gmail_server, gmail_port)
my_server.ehlo() #identify the client to the server
my_server.starttls() #enables encryption
#loggin in
my_server.login(my_email, password_key)
#import for text
from email.mime.text import MIMEText
#text content
text_content = "Sup Nigga, this an automated message"
#making the email
message.attach(MIMEText(text_content))
#import for image
from email.mime.image import MIMEImage
import os #using operating system
#getpath
Image_path = 'C:\\Users\\eashi\\OneDrive\\Documents\\PassNowTutoring\\PassNowTutoring\\Auto Email\\CSC.jpg'
#readimage
Image_img = open(Image_path, 'rb').read()
#Attach image to message
message.attach(MIMEImage(Image_img,name = os.path.basename(Image_path)))
#import for pdf
from email.mime.application import MIMEApplication
File_path = 'C:\\Users\\eashi\\OneDrive\\Documents\\PassNowTutoring\\PassNowTutoring\\Auto Email\\CSC2.pdf'
#ReadPdf
with open(File_path, 'rb') as f:
file = MIMEApplication(f.read(),name = os.path.basename(File_path))
file['Content-Disposition'] = f'attachment; filename = "{os.path.basename(File_path)}"'
message.attach(file)
#person receving the email
reciever = "eashimwe@gmail.com"
#sending the email
my_server.send_message( from_addr =my_email, to_addrs = reciever, msg =message)
#closing
my_server.quit()
print("email sent")