Skip to content

Commit eccc8e9

Browse files
committed
add send_mail and regex
1 parent 22d92c0 commit eccc8e9

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

py3/mail/send_mail.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
from email import encoders
5+
from email.header import Header
6+
from email.mime.text import MIMEText
7+
from email.utils import parseaddr, formataddr
8+
import smtplib
9+
10+
def _format_addr(s):
11+
name, addr = parseaddr(s)
12+
return formataddr((Header(name, 'utf-8').encode(), addr))
13+
14+
from_addr = input('From: ')
15+
password = input('Password: ')
16+
to_addr = input('To: ')
17+
smtp_server = input('SMTP server: ')
18+
19+
msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')
20+
msg['From'] = _format_addr('Python爱好者 <%s>' % from_addr)
21+
msg['To'] = _format_addr('管理员 <%s>' % to_addr)
22+
msg['Subject'] = Header('来自SMTP的问候……', 'utf-8').encode()
23+
24+
server = smtplib.SMTP(smtp_server, 25)
25+
server.set_debuglevel(1)
26+
server.login(from_addr, password)
27+
server.sendmail(from_addr, [to_addr], msg.as_string())
28+
server.quit()

py3/regex/regex.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import re
5+
6+
print('Test: 010-12345')
7+
m = re.match(r'^(\d{3})-(\d{3,8})$', '010-12345')
8+
print(m.group(1), m.group(2))
9+
10+
t = '19:05:30'
11+
print('Test:', t)
12+
m = re.match(r'^(0[0-9]|1[0-9]|2[0-3]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|[0-9])$', t)
13+
print(m.groups())

0 commit comments

Comments
 (0)