Python實現傳送郵件驗證碼

2021-10-14 10:00:12 字數 2717 閱讀 2591

import smtplib

import re

from os import environ

from os.path import exists

from platform import system,node

from time import strftime

from email.mime.text import mimetext

from email.utils import formataddr

from random import randint

from easygui import msgbox,enterbox

print

('庫載入完成'

)title =

'這是標題(請自行更改)'

my_sender =

'[email protected]'

#發件者郵箱(請自行更改)

my_pass =

'qfaqplfqzrzbmvwq'

#授權碼(請自行更改)

dt = strftime(

'%y-%m-%d %h:%m:%s'

)print

('已經獲取時間'

)my_user = usermail

username = environ[

'username'

]system = system(

)computer = node(

)number = randint(

100000

,999999

)#驗證碼

err = exception

print

('裝置資訊獲取完成\n變數定義完成'

)def

mail()

:global err

ret =

true

print

('巢狀入檢查語句'

)try

: msg = mimetext(

'這是郵件內容(請自行更改)'

,'plain'

,'utf-8'

) msg[

'from'

]= formataddr(

["發件人名稱(請自行更改)"

, my_sender]

) msg[

'to'

]= formataddr(

["fk"

, my_user]

) msg[

'subject']=

"***的驗證碼(請自行更改)"

print

('已經設定好郵件資訊'

)

server = smtplib.smtp_ssl(

"smtp.126.com"

,465

) server.login(my_sender, my_pass)

server.sendmail(my_sender,

[my_user,

], msg.as_string())

server.quit(

)print

('郵件傳送已完成'

)except exception as e:

ret =

false

err =

str(e)

print

('進入錯誤語句\n錯誤是%s'

%(err)

)return ret

print

('返回資訊'

)def

checkmail

(email)

:print

('進入驗證語句'

) reg =

"\w+[@][a-za-z0-9_]+(\.[a-za-z0-9_]+)+"

result = re.findall(reg,email)

if result:

ret = mail(

)if ret:

num = enterbox(

'傳送成功!請輸入您的驗證碼:'

,title)

if num ==

str(number)

:with

open

('canregister.txt'

,'w+'

,encoding =

'utf-8'

)as f:

f.write(

'canregister'

) msgbox(

'驗證成功!'

,title)

else

: msgbox(

'驗證失敗!'

,title)

else

: msgbox(

'郵件傳送失敗!\n原因是:%s'

%(err)

,title)

else

: msgbox(

'您的輸入不合法,請重新開啟程式輸入!'

,title)

if __name__ ==

'__main__'

:print

('進入主程式'

) checkmail(my_user)

django郵件傳送驗證碼

在我們使用 註冊賬號時,使用郵箱傳送驗證碼是很普遍的事。那麼下面就介紹使用django專案傳送郵箱驗證碼來進行驗證註冊。現在說一下在settings.py中的配置。email backend django.core.mail.backends.smtp.emailbackend email host...

安卓傳送郵件驗證碼

public static string myemailsmtphost smtp.qq.com public static string account qq.com 自己的郵箱 public static string password 密碼 int verificationcode int m...

python傳送簡訊驗證碼

import random code 驗證碼 for num in range 1,5 code code str random.randint 0,9 2 匯入sdk import zhenzismsclient as smsclient 3 呼叫簡訊平台傳送驗證碼 client smsclien...