-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailing_Script.py
40 lines (39 loc) · 1.29 KB
/
Mailing_Script.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
import smtplib
import time
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
def Sending_Mail():
try:
server=smtplib.SMTP('smtp.gmail.com: 587')
server.ehlo()
server.starttls()
server.ehlo()
server.login('Your Email','Your_Password')
msg=MIMEMultipart()
msg['From']='Your Email'
msg['To']='Receiver Email'
msg['Subject']='Automating Mails'
with open('Mail.txt','r') as f:
MailText=f.read()
msg.attach(MIMEText(MailText,'plain'))
filename='27.jpg'
attachment=open(filename,'rb')
payload=MIMEBase('application','octet_stream')
payload.set_payload(attachment.read())
encoders.encode_base64(payload)
payload.add_header('Content-disposition',f'attachment;f{filename}')
msg.attach(payload)
text=msg.as_string()
server.sendmail('Your Mail','Receiver Mail',text)
server.quit()
except:
print("Sorry We Couldn't Send Your Mail")
counter=0
while True:
if __name__=='__main__':
time.sleep(1)
Sending_Mail()
counter=counter+1
print('{} Mail Sent'.format(counter))