-
Notifications
You must be signed in to change notification settings - Fork 3
/
send
executable file
·58 lines (49 loc) · 1.51 KB
/
send
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
#!/usr/bin/env python3
"""
A python3 script for sending mails
Default is iitk cc smtp server
"""
import smtplib as sl
import getpass
def main():
"""
The main body
"""
username = input('Username : ')
passwd = getpass.getpass()
# Accepting user input
_from = input('From :')
send_to = input('Enter Recipient separated by commas: ').split(',')
cc = input('Cc : ').split(',')
bcc = input('Bcc : ').split(',')
sub = input('Sub :')
print('\nEnter Message end with ###: ')
sentinel = '###'
# Accept message terminated by sentinel
mes = '\n'.join(iter(input, sentinel))
print('Success!!')
print('\nSending from :\n' + _from)
print('\nSending to :\n' + str(send_to))
print('\nSending cc :\n' + str(cc))
print('\nSending bcc :\n' + str(bcc))
print('\nSubject\n' + sub)
print('\nMessage :\n' + mes)
# Only works form inside iitk
server = sl.SMTP('smtp.cc.iitk.ac.in', 25)
# For outside, use :
# server = sl.SMTP('mmtp.iitk.ac.in', 25)
# Below two lines are required for other servers
# server.starttls()
# server.ehlo()
server.login(username, passwd)
# Creating Header
to_send = "To: " + ", ".join(send_to)
cc_send = "Cc: " + ", ".join(cc)
from_send = "From: " + _from
sub_send = "Subject: " + sub
message = "\r\n".join([from_send, to_send, cc_send, sub_send, '', mes])
# Sending Mail
server.sendmail(_from, send_to + cc + bcc, message)
server.quit()
if __name__ == "__main__":
main()