-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmail.py
49 lines (39 loc) · 1.28 KB
/
Email.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
##################################################
## This is to send emails
##
##################################################
## GNU Lesser General Public License v3.0
##################################################
## Author: Patrick Hinson
## Copyright: Copyright 2019, email
## Credits: [Patrick Hinson]
## License: GNU Lesser General Public License v3.0
## Version: 1.0.0
## Mmaintainer: Patrick Hinson
## Email:
## Status: Stable
## Language: python
##################################################
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def email(mssubject, msfrom, msto, mstext, mshtml, mailserver):
try:
msg = MIMEMultipart('alternative')
msg['Subject'] = mssubject
msg['From'] = msfrom
msg['To'] = msto
part1 = MIMEText(mstext, 'plain')
part2 = MIMEText(mshtml, 'html')
msg.attach(part1)
msg.attach(part2)
except:
exerror = "email() -- Add message parts: ", sys.exc_info()[0]
print(exerror)
try:
s = smtplib.SMTP(mailserver)
s.sendmail(msfrom, msto, msg.as_string())
s.quit()
except:
exerror = "EMAIL email() -- Send email Unexpected error: ", sys.exc_info()[0]
print(exerror)