Python uses the smtplib module to send emails through gmail
This article mainly introduces how to use the smtplib module in python to send emails through gmail. It involves the skills related to sending emails using the smtplib module in Python. It is very simple and practical. If you need it, you can refer
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Import smtplib From email. MIMEMultipart import MIMEMultipart From email. MIMEText import MIMEText Fromaddr = 'fromaddr @ gmail.com' Toaddr = 'toaddr @ gmail.com' Text = 'test email message sent from Python Code' Username = 'fromaddruser' Password = 'fromaddrpassword' Msg = MIMEMultipart () Msg ['from'] = fromaddr Msg ['to'] = toaddr Msg ['subobject'] = 'test' Msg. attach (MIMEText (text )) Server = smtplib. SMTP ('smtp .gmail.com: 8080 ') Server. ehlo () Server. starttls () Server. ehlo () Server. login (username, password) Server. sendmail (fromaddr, toaddr, msg. as_string ()) Server. quit () |
I hope this article will help you with Python programming.