-
Notifications
You must be signed in to change notification settings - Fork 0
/
mime.py
49 lines (35 loc) · 1.26 KB
/
mime.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
import configparser
import smtplib
def add_smime_header(msg):
header = """MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64\n\n"""
return header + msg
def add_opgp_header(msg):
header = """Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; boundary="123"
--123>
Content-Type: application/pgp-encrypted
Content-Description: PGP/MIME version identification
Version: 1
--123
Content-Type: application/octet-stream; name="encrypted.asc"
Content-Description: OpenPGP encrypted message
Content-Disposition: inline; filename="encrypted.asc"
"""
end = "\n--123--"
return header + msg + end
def send_mail(eml):
# Load config
config = configparser.ConfigParser()
config.read('config.txt')
# Load credentials
server_addr = config['DEFAULT']['serveraddr']
login_name = config['DEFAULT']['loginname']
from_addrs = to_addrs = config['DEFAULT']['emailaddr']
password = config['DEFAULT']['password']
# Connect to server and send email
server = smtplib.SMTP(server_addr)
server.login(login_name, password)
server.sendmail(from_addrs, to_addrs, eml)
server.quit()