blob: 6286ef2e8e65785c085e8613ce5da1533db99cca (
plain) (
blame)
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
|
from getpass import getpass
import smtplib
def prompt(prompt):
return raw_input(prompt).strip()
# 4. Read data from stdin
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print '\nEnter headers, end with \\r\\n\\r\\n:'
headers = 'From: %s\r\nTo: %s\r\n' % (fromaddr, ', '.join(toaddrs))
while True:
try:
line = raw_input()
except EOFError:
break
if not line:
break
headers = headers + line
print 'Enter message, end with ^D:'
msg = ''
while 1:
try:
line = raw_input()
except EOFError:
break
msg = msg + '\r\n' + line
msg = headers + msg
# 1 & 2. Connection and upgrading to STARTTLS
server = smtplib.SMTP('smtp.science.ru.nl')
server.starttls()
# 3. Authentication
print('\nPlease enter your science login information.')
while True:
user = prompt("User: ")
password = getpass("Pass: ")
try:
server.login(user, password)
break
except smtplib.SMTPAuthenticationError:
print('Incorrect credentials, try again.')
# 4. Send mail
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
|