Send simple emails using Python

xiaoxiao2021-03-06  65

A few more time, some people discuss how to use Python to send mail that you need to authenticate, I analyzed the SMTP server in my FreeBSD in Telnet to 163, analyzed the program that sent mail with Python, and it feels a bit rough. But it is still possible to work. Import Smtplib, Base64

class SimpleSendMail: def __init __ (self, smtp_server, from_addr, to_addr, user, passwd): self.from_addr = from_addr self.to_addr = to_addr self.username = base64.encodestring (user) self.password = base64.encodestring (passwd) self .mailserver = SMTP_SERVER DEF Send (Self, MSG): Server = SMTPLIB.SMTP (Self.mailServer) Server.Set_Debuglevel (1) Server.docmd ("Ehlo Server) Server.DOCMD (" Auth login "Server.send Self.Username) Server.getReply () Server.send (Self.Password) Server.getReply () Server.docmd ("Mail from:" Self.From_Addr) Server.docmd ("RCPT TO:" SELF.TO_ADDR) Server.docmd ("Data") Server.send (MSG) Server.send ("/ R / n. / r / n") server.getReply () # server.reset () server.quit () if __name__ == '__main__': test = simplesendmail ("smtp.163.com", "xxxx@163.com", "xxxx@sina.com", "xxxx", "xxxxxxxxx") TEST.SEND ("HeheH / R / NA Test From Python Send Mail ")

转载请注明原文地址:https://www.9cbs.com/read-110190.html

New Post(0)