Login in Process
- 2 step process
- password login
- Mobile phone confirmation
- google Gmail 無法support python 2 step verification
- 可用 google App Password 處理 (應用程式密碼)


- google APP password
- 建立google 兩步驟機制
- 建立應用程式密碼 _ 16字元password
- 不建議直接hard code 寫出 account / password
- ex smtp.login(”[email protected]”, “ 12345”)
- 增加scurity
- 改用 email = input ( “ enter your email_” )
- 改用 password = input ( “ enter your password_” )
- smtp.login(email, password)
- 更保密的方法 用 import getpass
- getpass.getpass( ) —> 讓key in 不會出現在terminal 中
import smtplib
smtp_ojb = smtplib.SMTP("smtp.gmail.com",587) # 建立mail server 連線 /跟 加密port 587
print(smtp_ojb.ehlo()) #確認是否有連上線
print(smtp_ojb.starttls())
smtp_ojb.login("[email protected]","xxxxxxxxxxx") # 直接用hard copy 不建議
-----------------
(250, b'smtp.gmail.com at your service, [122.116.213.45]\\nSIZE 35882577\\n8BITMIME\\nSTARTTLS\\nENHANCEDSTATUSCODES\\nPIPELINING\\nSMTPUTF8')
(220, b'2.0.0 Ready to start TLS')
Process finished with exit code 0
---------------------------------
# getpass for protect password
import smtplib
import getpass
smtp_ojb = smtplib.SMTP("smtp.gmail.com",587) # 建立mail server 連線 /跟 加密port 587
print(smtp_ojb.ehlo()) #確認是否有連上線
print(smtp_ojb.starttls())
email = input("enter your email:")
password = getpass.getpass("enter your password: ") # getpass for protect password
smtp_ojb.login(email,password)
------------------------
(235, b'2.7.0 Accepted') --> print 出來result
