micromail/examples/example.py

38 lines
793 B
Python

import ntptime
from machine import RTC
from micromail import MicromailClient
# Use NTP to synchronize time
rtc = RTC()
ntptime.settime()
# Create an SMTP client
client = MicromailClient(
host="mail.example.com",
port=465,
ssl=True,
)
# Connect to the server
client.connect()
# Login to the server
client.login("example@example.com", "password")
# Initialize a new message
client.new_message("example@example.org")
# Set message headers
client.headers(
{
"from": "Example <example@example.com>",
"subject": "Test",
"to": "Example <example@example.org>",
}
)
# Write message content
client.write_line("Hello world!")
client.write_line("Ceci est un message très intéressant.")
client.write_line("...")
# Send message
client.send()
client.quit()