-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mail.py
30 lines (27 loc) · 992 Bytes
/
Mail.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
#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
class Mail:
__smtpHost: str
__smtpPort: int
__smtpUser: str
__smtpCode: str
__mailSender: str
__mailReceiver: str
def __init__(self, smpthost: str, smtpPort: int, smtpUser: str, smtpCode: str, mailSender: str, mailReceiver: str):
self.__smtpHost = smpthost
self.__smtpPort = smtpPort
self.__smtpUser = smtpUser
self.__smtpCode = smtpCode
self.__mailSender = mailSender
self.__mailReceiver = mailReceiver
def send(self,message: str, subject: str):
server = smtplib.SMTP(self.__smtpHost, self.__smtpPort)
server.starttls()
server.login(self.__smtpUser, self.__smtpCode)
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = self.__mailSender
msg['To'] = self.__mailReceiver
server.sendmail(self.__mailSender, self.__mailReceiver, msg.as_string())
server.quit()