Login in Process

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

Untitled

Untitled

  1. google APP password
    1. 建立google 兩步驟機制
    2. 建立應用程式密碼 _ 16字元password
      1. 不建議直接hard code 寫出 account / password
        1. ex smtp.login(”[email protected]”, “ 12345”)
      2. 增加scurity
        1. 改用 email = input ( “ enter your email_” )
        2. 改用 password = input ( “ enter your password_” )
        3. smtp.login(email, password)
          1. 更保密的方法 用 import getpass
            1. 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 

Untitled