Send email from an Arduino
Box IO sends mail through the SMTP account saved in admin Settings. The sketch calls BoxIO.email. The board does not talk to the mail host itself, and the sketch does not contain the password.
Save SMTP on the server
- Sign in as admin at
http://localhost. - Open Settings and find SMTP email.
- Set Host, Port, Username, Password, and From address.
- Set Use TLS/SSL to STARTTLS for port 587, or implicit TLS for port 465.
- Click Save settings.
- Type an address and click Send test email. The page says the test email was sent when SMTP works.
Use a mailbox you control: Google Workspace, Gmail with an app password, Microsoft 365, or any other SMTP host. Email is optional. The dashboard runs without it.
Call it from the sketch
BoxIO.email(to, subject, body) returns true when the server accepts the request. If SMTP is not saved, the server rejects it and the call returns false. Keep BoxIO.run() in loop(). Email is not counted in the virtualWrite rate cap.
Keep the text short. The library URL-encodes the address and subject into 80-character buffers and the body into a 120-character buffer. A longer body is cut off on the board. On a classic AVR the whole request also has to fit in a 192-character path.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
// SMTP username and password stay in admin Settings.
}
void loop() {
BoxIO.run();
static uint32_t last = 0;
if (millis() - last < 60000) return;
last = millis();
BoxIO.email("you@example.com", "Pump", "Water level is high");
}
What you should see
The test button delivers one message before you flash anything. After the sketch runs, the same From address sends “Pump” to the address in BoxIO.email. A failed call means Settings is missing a host, the password is wrong, or the message was too long for the board buffer.