# python email sender [Github](https://github.com/careful12/python-email-sending) ref: [Code With Tomi - Send Emails With Python [UPDATED]](https://www.youtube.com/watch?v=zxFXnLEmnb4&ab_channel=CodeWithTomi) --- ## Before coding | Step 1 | Step 2 | | -------- | -------- | |<img src=https://i.imgur.com/136Fs6b.png >|<img src=https://i.imgur.com/kHodizq.png>| |Step 3 | | -------- | |<img src=https://i.imgur.com/ROzth3q.png> **需先完成兩步驟認證**| |Step 4| |------| || |Step 5| |------| || |Step 6| | ------ | | **複製他給的密碼**| ## Start coding **Step 7 - finish code** ```python from email.message import EmailMessage import ssl import smtplib # set the sender # your gmail email_sender = 'b00303333@gmail.com' # generate form step 6 email_password = password # set the receiver email_receiver = '' # set the subject and content subject = "Python email test" body = """ Python email test """ # email message oject em = EmailMessage() # set headers em['From'] = email_sender # or em.add_header("From", email.sender) em['To'] = email_receiver em['subject'] = subject # set content em.set_content(body) context = ssl.create_default_context() with smtplib.SMTP_SSL(host='smtp.gmail.com', port=465, context=context) as smtp: smtp.login(email_sender, email_password) smtp.sendmail(email_sender, email_receiver, em.as_string()) ``` |Step 8| |------| |到 [https://temp-mail.org/](https://temp-mail.org/) 測試| **Step 9** - 將複製的email貼到email_receiver ```python # set the receiver email_receiver = '' ``` **Step 10 - Execute Your Code** --- |測試結果| |------| | |
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up