7.10. smtp — SMTP protocol

The smtp module provides functions for related to the smtp protocol

7.10.1. Functions

smtp.account_init(tuple)

Set the account information .

The function’s parameter is a 6-tuple with the following structure:

((ACCOUNT_EMAIL_ADDRESS, ACCOUNT_USERNAME, ACCOUNT_PASSWORD, ACCOUNT_SMTP_SERVER, ACCOUNT_SMTP_SERVER_PORT, ACCOUNT_ENCRYPTION_TLS ))

smtp.account_deinit()

Deinitialize the account.

smtp.send(tuple)

Send email through the account

The function’s parameter is a 6-tuple with the following structure:

((EMAIL_TO_ADDRESS, EMAIL_CC_ADDRESS, EMAIL_BCC_ADDRESS, EMAIL_SUBJECT, EMAIL_CONTENT, length of EMAIL_CONTENT ))

# E-mail Wubby Example (showcase SNTP and SMTP protocols)

import smtp
import time

# Account Settings
ACCOUNT_EMAIL_ADDRESS    = "wubby.demo@gmail.com"
ACCOUNT_USERNAME         = "wubby.demo"
ACCOUNT_PASSWORD         = "Wu66yP@ssw0rd"
ACCOUNT_SMTP_SERVER      = "smtp.gmail.com"
ACCOUNT_SMTP_SERVER_PORT = 587
ACCOUNT_ENCRYPTION_TLS   = 1
#ACCOUNT_ENCRYPTION_NONE   = 0

# E-mail content
EMAIL_TO_ADDRESS  = "info@wubby.io"
EMAIL_CC_ADDRESS  = ""
EMAIL_BCC_ADDRESS = ""
EMAIL_SUBJECT     = "Hello from Wubby!"
EMAIL_CONTENT     = "This email has been sent from a Wubby device!"

print("Wubby e-mail example")

# Initialise e-mail account
smtp.account_init((ACCOUNT_EMAIL_ADDRESS, ACCOUNT_USERNAME, ACCOUNT_PASSWORD, ACCOUNT_SMTP_SERVER, ACCOUNT_SMTP_SERVER_PORT, ACCOUNT_ENCRYPTION_TLS ))

# Prepare e-mail content
smtp.send((EMAIL_TO_ADDRESS, EMAIL_CC_ADDRESS, EMAIL_BCC_ADDRESS, EMAIL_SUBJECT, EMAIL_CONTENT, len(EMAIL_CONTENT) ))

# Cleanup
smtp.account_deinit()

while True:
    time.sleep(5)