-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollective-mail.py
53 lines (45 loc) · 1.47 KB
/
collective-mail.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
46
47
48
49
50
51
52
53
import smtplib
import webbrowser
import sys
import time
import getpass
from colored import fg, bg, attr
color = fg('green')
reset = attr('reset')
try:
file1 = open('collective-mail-header.txt', 'r')
print(' ')
print (color + file1.read() + reset)
file1.close()
except IOError:
print('\nBanner File not found!')
userid = input("\nEnter your G-Mail id :\t")
passwd = getpass.getpass("\nEnter your Password :\t")
subj = input("\nEnter the Subject (optional) :\n\n")
body = input("\nEnter the Message :\n\n")
message = ("From :\t" + userid + "\nSubject :\t" + subj + "\n" + body)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
try:
server.login(userid, passwd)
except smtplib.SMTPAuthenticationError:
print("\nYour G-Mail id or Password maybe incorrect!!!\n")
print("\nOr maybe you have disabled Less-Secure-Apps on your G-Mail account!!!\n")
resp = int(input("\nEnter 1 to enable Less-Secure-Apps now or Enter 0 to ignore :\n\n"))
if (resp == 1):
webbrowser.open('http://myaccount.google.com/lesssecureapps', new=2)
sys.exit()
n = int(input("\nEnter no. of G-Mail accounts you want to send this mail to :\t"))
for i in range (0,n):
target = input("\nEnter G-Mail id no." + str(i+1) + " :\t")
try:
server.sendmail(userid, target, message)
print ("\nSuccessfully sent Mail to " + str(i+1) + " Account !!!\n")
time.sleep(1)
except KeyboardInterrupt:
print ("\nCanceled!!!\n")
sys.exit()
except:
print ("\nFailed to Send!!!\n")
server.close()