.
.
.参考:https://www.runoob.com/python3/python3-smtp.html
#encoding=utf-8 ‘‘‘ Created on 2019年10月11日 @author: sea ‘‘‘ import smtplib from email.mime.text import MIMEText from email.header import Header def send(From,to,subject,content): ‘‘‘ send(From,to,subject,content) ‘‘‘ sendMsg(to,subject,content,From) def sendTo(to,subject,content): ‘‘‘sendTo(to,subject,content)‘‘‘ sendMsg(to,subject,content) def sendMsg(To,Subject,Content,From=‘[email protected]‘,Host=‘192.168.16.253‘): message = MIMEText(Content, ‘plain/html‘, ‘utf-8‘) message[‘Subject‘] = Header(Subject, ‘utf-8‘) message[‘From‘] = From # 发送者 message[‘To‘] = ‘‘ # 接收者 for receiver in To: message[‘To‘]+=receiver try: ‘‘‘if is 3rd email‘‘‘ # smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号 mail_host ="smtp.XXX.com" #设置服务器 # smtpObj.login(mail_user,mail_pass) //登录用户名,密码 smtpObj = smtplib.SMTP(Host,25) smtpObj.sendmail(From, To, message.as_string()) print ("邮件发送成功") except smtplib.SMTPException: print ("Error: 无法发送邮件") if __name__ == ‘__main__‘: From = ‘[email protected]‘ To = [‘[email protected]‘,"[email protected]"] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 Subject = ‘Python SMTP 邮件测试 hahhahhaahahahah toototoootoot‘ Content="‘Python 邮件发送测试...‘" Host=‘192.168.16.253‘ # send(From, To, Subject, Content) sendTo(To, Subject, Content)
原文地址:https://www.cnblogs.com/lshan/p/11653762.html
时间: 2024-10-29 08:41:43