tempmail python
2.3.3 - Python 3.7+ support
tempmail-python เป็นไลบรารี Python สำหรับสร้างและจัดการที่อยู่อีเมลชั่วคราวโดยใช้บริการ 1secmail มีฟังก์ชันสำหรับสร้างที่อยู่อีเมล ตรวจสอบข้อความใหม่ และดึงเนื้อหาข้อความ
คุณสามารถติดตั้ง tempmail-python โดยใช้ pip:
pip install tempmail-python
หรือคุณสามารถติดตั้งได้จากแหล่งที่มา:
pip install git+https://github.com/cubicbyte/tempmail-python.git
รับข้อความ (เช่น รหัสเปิดใช้งาน)
from tempmail import EMail
email = EMail ()
print ( email . address ) # [email protected]
# ... request some email ...
msg = email . wait_for_message ()
print ( msg . body ) # Hello World!n
รับข้อความทั้งหมดในกล่องจดหมาย
from tempmail import EMail
email = EMail ( '[email protected]' )
inbox = email . get_inbox ()
for msg_info in inbox :
print ( msg_info . subject , msg_info . message . body )
ดาวน์โหลดไฟล์แนบ
from tempmail import EMail
email = EMail ( username = 'example' , domain = '1secmail.com' )
msg = email . wait_for_message ()
if msg . attachments :
attachment = msg . attachments [ 0 ]
data = attachment . download ()
# Print
print ( data ) # b'Hello World!n'
print ( data . decode ( 'utf-8' )) # Hello World!n
# Save to file
with open ( attachment . filename , 'wb' ) as f :
f . write ( data )
รับรหัสเปิดใช้งาน Reddit
from tempmail import EMail
def reddit_filter ( msg ):
return ( msg . from_addr == '[email protected]' and
msg . subject == 'Verify your Reddit email address' )
email = EMail ( address = '[email protected]' )
msg = email . wait_for_message ( filter = reddit_filter )
# get_activation_code(html=msg.html_body)
คุณสมบัติอื่นๆ:
from tempmail . providers import OneSecMail
email = OneSecMail ()
# request_email(email=email.address)
# Speed up inbox refresh rate
OneSecMail . inbox_update_interval = 0.1 # every 100ms
# Accept only emails with a specific subject, raise error after 60 seconds
msg = email . wait_for_message ( timeout = 60 , filter = lambda m : m . subject == 'Hello World!' )
print ( msg . body )
tempmail-python ได้รับอนุญาตภายใต้ใบอนุญาต MIT ดูไฟล์ใบอนุญาตสำหรับข้อมูลเพิ่มเติม