mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-12 12:42:50 +08:00

Some checks failed
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, , mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, , test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, BUILTIN, mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (clang++, BUILTIN, test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, , mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, , test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, BUILTIN, mip_test) (push) Has been cancelled
Build and test - essentials / linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }} (gcc, BUILTIN, test) (push) Has been cancelled
Build and test - essentials / s390 (push) Has been cancelled
Build and test - essentials / armhf (push) Has been cancelled
Build and test - essentials / unamalgamated-mg_prefix (push) Has been cancelled
Build and test - essentials / macos SSL=${{ matrix.ssl }} () (push) Has been cancelled
Build and test - essentials / macos SSL=${{ matrix.ssl }} (BUILTIN) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (mingw++) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (vc22) (push) Has been cancelled
Build and test - essentials / windows ${{ matrix.target }} (vc98) (push) Has been cancelled
Build and test - essentials / arm (push) Has been cancelled
Build and test - essentials / riscv (push) Has been cancelled
Build and test - essentials / examples (push) Has been cancelled
Build and test - essentials / examples_win (push) Has been cancelled
Build and test - essentials / examples_mac (push) Has been cancelled
Build and test - essentials / refprojs (push) Has been cancelled
Build and test - essentials / refprojs_win (push) Has been cancelled
Build and test - essentials / refprojs_mac (push) Has been cancelled
Build and test - essentials / tutorials (push) Has been cancelled
Build and test - essentials / tutorials_win (push) Has been cancelled
Build and test - essentials / tutorials_mac (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:infineon/infineon-xmc7200]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/frdm-mcxn947-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/frdm-mcxn947-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1020-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1060-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1170-evk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-2-w-picosdk-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-w-picosdk-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/w5500-evb-pico-picosdk-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/w5500-evb-pico2-picosdk-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f429zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f429zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h563zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h563zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h723zg-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h723zg-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h743zi-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-h743zi-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/stm32h573i-dk-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/stm32h573i-dk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:ti/ek-tm4c1294xl-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:ti/ek-tm4c1294xl-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp32/uart-bridge]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp8266/http-client-server]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:infineon/infineon-xmc4700_4800-lwip-rtx-rtos]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-g031-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:esp32/device-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:microchip/same54-xpro/device-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1020-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1060-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:nxp/rt1170-evk-make-freertos-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-2-w-picosdk-freertos-lwip]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-rndis-dashboard]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-w-picosdk-freertos-lwip]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:renesas/ek-ra6m4-make-baremetal-builtin]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-baremetal-builtin-cmsis_driver]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:stm32/nucleo-f746zg-make-freertos-tcp]) (push) Has been cancelled
Build and test - essentials / ${{ matrix.example.path }} (map[path:pico-sdk/pico-rndis-device]) (push) Has been cancelled
Build and test - essentials / cube_examples (push) Has been cancelled
Build and test - essentials / test_f7 (push) Has been cancelled
Build and test - essentials / test_f4 (push) Has been cancelled
Build and test - essentials / test_h743 (push) Has been cancelled
Build and test - essentials / test_h723 (push) Has been cancelled
Build and test - essentials / test_h5 (push) Has been cancelled
Build and test - essentials / test_rt1020 (push) Has been cancelled
Build and test - essentials / test_rt1060 (push) Has been cancelled
Build and test - essentials / test_rt1170 (push) Has been cancelled
Build and test - essentials / test_ra6m4 (push) Has been cancelled
Build and test - essentials / test_tm4c (push) Has been cancelled
Build and test - essentials / test_same54 (push) Has been cancelled
Build and test - essentials / test_pico_w5500 (push) Has been cancelled
84 lines
3.0 KiB
C
84 lines
3.0 KiB
C
#include "mongoose.h"
|
|
|
|
static const char *server = "tcp://smtp.gmail.com:587";
|
|
static const char *user = "aaa@domain.com"; // Change this! Your mail account
|
|
static const char *pass = "xxxxxxxxxxxxxx"; // Change this! Your mail password
|
|
static const char *to = "bbb@domain.com"; // Change this! Destination email
|
|
|
|
static const char *from = "My Mail Sender";
|
|
static const char *subj = "Test email from Mongoose library!";
|
|
static const char *mesg = "Hi!\nThis is a test message.\nBye.";
|
|
|
|
static bool s_quit;
|
|
|
|
enum { EHLO, STARTTLS, STARTTLS_WAIT, AUTH, FROM, TO, DATA, BODY, QUIT, END };
|
|
|
|
static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
|
uint8_t *state = (uint8_t *) c->data;
|
|
if (ev == MG_EV_OPEN) {
|
|
// c->is_hexdumping = 1;
|
|
} else if (ev == MG_EV_READ) {
|
|
if (c->recv.len > 0 && c->recv.buf[c->recv.len - 1] == '\n') {
|
|
MG_INFO(("<-- %.*s", (int) c->recv.len - 2, c->recv.buf));
|
|
c->recv.len = 0;
|
|
if (*state == EHLO) {
|
|
mg_printf(c, "EHLO myname\r\n");
|
|
*state = STARTTLS;
|
|
} else if (*state == STARTTLS) {
|
|
mg_printf(c, "STARTTLS\r\n");
|
|
*state = STARTTLS_WAIT;
|
|
} else if (*state == STARTTLS_WAIT) {
|
|
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
|
|
.name = mg_url_host(server)};
|
|
mg_tls_init(c, &opts);
|
|
mg_tls_handshake(c); // speed up, not strictly necessary
|
|
*state = AUTH;
|
|
} else if (*state == AUTH) {
|
|
char a[100], b[300] = "";
|
|
size_t n = mg_snprintf(a, sizeof(a), "%c%s%c%s", 0, user, 0, pass);
|
|
mg_base64_encode((uint8_t *) a, n, b, sizeof(b));
|
|
mg_printf(c, "AUTH PLAIN %s\r\n", b);
|
|
*state = FROM;
|
|
} else if (*state == FROM) {
|
|
mg_printf(c, "MAIL FROM: <%s>\r\n", user);
|
|
*state = TO;
|
|
} else if (*state == TO) {
|
|
mg_printf(c, "RCPT TO: <%s>\r\n", to);
|
|
*state = DATA;
|
|
} else if (*state == DATA) {
|
|
mg_printf(c, "DATA\r\n");
|
|
*state = BODY;
|
|
} else if (*state == BODY) {
|
|
mg_printf(c, "From: %s <%s>\r\n", from, user); // Mail header
|
|
mg_printf(c, "Subject: %s\r\n", subj); // Mail header
|
|
mg_printf(c, "\r\n"); // End of headers
|
|
mg_printf(c, "%s\r\n", mesg); // Mail body
|
|
mg_printf(c, ".\r\n"); // End of body
|
|
*state = QUIT;
|
|
} else if (*state == QUIT) {
|
|
mg_printf(c, "QUIT\r\n");
|
|
*state = END;
|
|
} else {
|
|
c->is_draining = 1;
|
|
MG_INFO(("end"));
|
|
}
|
|
MG_INFO(("--> %.*s", (int) c->send.len - 2, c->send.buf));
|
|
}
|
|
} else if (ev == MG_EV_CLOSE) {
|
|
s_quit = true;
|
|
} else if (ev == MG_EV_TLS_HS) {
|
|
MG_INFO(("TLS handshake done! Sending EHLO again"));
|
|
mg_printf(c, "EHLO myname\r\n");
|
|
}
|
|
(void) ev_data;
|
|
}
|
|
|
|
int main(void) {
|
|
struct mg_mgr mgr;
|
|
mg_mgr_init(&mgr);
|
|
mg_log_set(MG_LL_DEBUG);
|
|
mg_connect(&mgr, server, fn, NULL);
|
|
while (s_quit == false) mg_mgr_poll(&mgr, 1000);
|
|
return 0;
|
|
}
|