-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendReport.py
36 lines (31 loc) · 1.01 KB
/
sendReport.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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
# Set up sender, receiver, and message details
fromaddr = "[email protected]"
toaddr = "[email protected]"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Subject of the Mail"
# Body of the email
body = "This is the body of the email"
msg.attach(MIMEText(body, 'plain'))
# Attachment
filename = "your_attachment.txt"
attachment = open("path_to_file", "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
# SMTP configuration
server = smtplib.SMTP('smtp.example.com', 587)
server.starttls()
server.login(fromaddr, "YourPassword")
text = msg.as_string()
# Send the email
server.sendmail(fromaddr, toaddr, text)
server.quit()