-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendemail.py
More file actions
28 lines (21 loc) · 835 Bytes
/
sendemail.py
File metadata and controls
28 lines (21 loc) · 835 Bytes
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
import email
import mimetypes
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
user = "kasterma@kasterma.net"
pw = "zw3y65k788hecch9"
server = smtplib.SMTP_SSL(host="smtp.fastmail.com", port=465)
server.login(user=user, password=pw)
msg = MIMEMultipart()
msg['To'] = "kasterma@kastermaa.net"
msg['From'] = "kasterma@kasterma.net"
msg['Subject'] = "With file attached"
with open("test_sheet.xlsx", "rb") as f:
mt = mimetypes.guess_type("test_sheet.xlsx")[0].split("/")
msg_file = MIMEBase(mt[0], mt[1])
msg_file.set_payload(f.read())
email.encoders.encode_base64(msg_file)
msg_file.add_header('Content-Disposition', 'attachment', filename="test_sheetttt.xlsx")
msg.attach(msg_file)
server.sendmail("kasterma@kasterma.net", "bart.kastermans@kpn.com", msg.as_string())