| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy | |||
| 56 | 56 | - [How to Automate your VPS or Dedicated Server Management in Python](https://www.thepythoncode.com/article/automate-veesp-server-management-in-python). ([code](general/automating-server-management)) | |
| 57 | 57 | - [How to Execute BASH Commands in a Remote Machine in Python](https://www.thepythoncode.com/article/executing-bash-commands-remotely-in-python). ([code](general/execute-ssh-commands)) | |
| 58 | 58 | - [How to Manipulate IP Addresses in Python using ipaddress module](https://www.thepythoncode.com/article/manipulate-ip-addresses-using-ipaddress-module-in-python). ([code](general/ipaddress-module)) | |
| 59 | + - [How to Send Emails in Python using smtplib Module](https://www.thepythoncode.com/article/sending-emails-in-python-smtplib). ([code](general/email-sender)) | ||
| 59 | 60 | ||
| 60 | 61 | - ### [Web Scraping](https://www.thepythoncode.com/topic/web-scraping) | |
| 61 | 62 | - [How to Access Wikipedia in Python](https://www.thepythoncode.com/article/access-wikipedia-python). ([code](web-scraping/wikipedia-extractor)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + # [How to Send Emails in Python using smtplib Module](https://www.thepythoncode.com/article/sending-emails-in-python-smtplib) | ||
| 2 | + Feel free to edit the code how ever you want to suit your needs! | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + import smtplib | ||
| 2 | + from email.mime.text import MIMEText | ||
| 3 | + from email.mime.multipart import MIMEMultipart | ||
| 4 | + from email.mime.audio import MIME | ||
| 5 | + | ||
| 6 | + # your credentials | ||
| 7 | + email = "email@example.com" | ||
| 8 | + password = "password" | ||
| 9 | + | ||
| 10 | + # the sender's email | ||
| 11 | + FROM = "email@example.com" | ||
| 12 | + # the receiver's email | ||
| 13 | + TO = "to@example.com" | ||
| 14 | + # the subject of the email (subject) | ||
| 15 | + subject = "Just a subject" | ||
| 16 | + | ||
| 17 | + # initialize the message we wanna send | ||
| 18 | + msg = MIMEMultipart() | ||
| 19 | + # set the sender's email | ||
| 20 | + msg["From"] = FROM | ||
| 21 | + # set the receiver's email | ||
| 22 | + msg["To"] = TO | ||
| 23 | + # set the subject | ||
| 24 | + msg["Subject"] = subject | ||
| 25 | + # set the body of the email | ||
| 26 | + text = MIMEText("This email is sent using <b>Python</b> !", "html") | ||
| 27 | + # attach this body to the email | ||
| 28 | + msg.attach(text) | ||
| 29 | + # initialize the SMTP server | ||
| 30 | + server = smtplib.SMTP("smtp.gmail.com", 587) | ||
| 31 | + # connect to the SMTP server as TLS mode (secure) and send EHLO | ||
| 32 | + server.starttls() | ||
| 33 | + # login to the account using the credentials | ||
| 34 | + server.login(email, password) | ||
| 35 | + # send the email | ||
| 36 | + server.sendmail(FROM, TO, msg.as_string()) | ||
| 37 | + # terminate the SMTP session | ||
| 38 | + server.quit() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments