Learning immediately: https://edu.csdn.net/course/play/24797/282212?utm_source=blogtoedu
smtplib Import, email.message, email.utils fromaddr = '[email protected]' password = '********************************************************' first_cid = email.utils.make_msgid () Conn smtplib.SMTP_SSL = ( 'smtp.qq.com', 465) conn.set_debuglevel (10) result = conn.login (fromaddr, password) Print ( 'mailbox login result:', result) MSG = email.message.EmailMessage ( ) msg.set_content ( '<h1 of> Python mail transmission </ h1 of>' + '<IMG the src = "CID:' + first_cid [. 1: -1] + '" />' + '<font Color = "Red" ') size = "20px"> test file </ font>', 'html ', 'UTF-8 relating to the message # msg [' subject '] =' python test messages' # Sender MSG [ 'from'] = 'Hello World <% S>'% fromaddr # recipient msg['to'] = 'hello world <%s>' % '37*****[email protected]' # 附件 with open('1.png', 'rb', True)as f: msg.add_attachment(f.read(), maintype='image', subtype='png', filename='itDay.png', cid=first_cid) with open('1.png', 'rb', True)as f: msg.add_attachment(f.read(), maintype='image', subtype='png', filename='itDay.png') conn.send_message(msg, fromaddr) conn.quit()