MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / SendMail

Class SendMail

class/mailModel/mainModel.py:77–526  ·  view source on GitHub ↗

发件类

Source from the content-addressed store, hash-verified

75
76
77class SendMail:
78 '''
79 发件类
80 '''
81 __setupPath = '/www/server/panel/plugin/mail_sys'
82 _session_conf = __setupPath + '/session.json'
83
84 def __init__(self, username, password, server, port=25, usettls=False):
85 self._session = self._get_session()
86 self.mailUser = username
87 self.mailPassword = password
88 self.smtpServer = server
89 self.smtpPort = port
90 self.mailServer = smtplib.SMTP(self.smtpServer, self.smtpPort)
91 if usettls:
92 self.mailServer.starttls()
93 self.mailServer.ehlo()
94 self.mailServer.login(self.mailUser, self.mailPassword)
95 self.msg = MIMEMultipart()
96 self.mailbox_list = [
97 'gmail.com',
98 'googlemail.com',
99 'hotmail.com',
100 'outlook.com',
101 'yahoo.com',
102 'protonmail.com',
103 'zoho.com',
104 'icloud.com',
105 ]
106
107 def __del__(self):
108 self.mailServer.close()
109
110 # 更新到初始的无内容无主题状态
111 def update_init(self, name):
112 self.msg = MIMEMultipart()
113 sender = formataddr((name, self.mailUser))
114 self.msg['From'] = sender
115 self.msg['Date'] = formatdate(localtime=True)
116
117 def nwe_msg(self, msgid):
118 msg = MIMEMultipart()
119 msg['Subject'] = self.msg['Subject']
120 msg['From'] = self.msg['From']
121 msg['Date'] = self.msg['Date']
122 msg['Message-ID'] = msgid
123
124 # unsubscribe_mailto = 'mailto:lotk1@moyumao.top'
125 # unsubscribe_url = 'https://bbb.moyumao.top/mailUnsubscribe?action=Unsubscribe&jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Ijk3NzkzNTUwMUBxcS5jb20iLCJleHAiOjE3MzI2MTcyNTB9.aXDSxtem1eAvcjYIlgkVr0I0CGNmPlcq4yAx5eEYHTI'
126 # # self.msg.add_header('List-Unsubscribe', f'<{unsubscribe_url}>, <{unsubscribe_mailto}>')
127 # msg['List-Unsubscribe'] = f'<{unsubscribe_mailto}>, <{unsubscribe_url}>'
128
129 msg.set_payload(self.msg.get_payload())
130
131 return msg
132
133 def _get_session(self):
134 session = public.readFile(self._session_conf)

Callers 5

send_mail_testMethod · 0.90
_send_email_allMethod · 0.90
send_mailMethod · 0.85
send_mail_httpMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected