1 /* 2 * libwebsockets - small server side websockets and web server implementation 3 * 4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 /** \defgroup smtp SMTP related functions 26 * ##SMTP related functions 27 * \ingroup lwsapi 28 * 29 * These apis let you communicate with a local SMTP server to send email from 30 * lws. It handles all the SMTP sequencing and protocol actions. 31 * 32 * Your system should have postfix, sendmail or another MTA listening on port 33 * 25 and able to send email using the "mail" commandline app. Usually distro 34 * MTAs are configured for this by default. 35 * 36 * You can either use the abstract protocol layer directly, or instead use the 37 * provided smtp sequencer... this takes care of creating the protocol 38 * connections, and provides and email queue and retry management. 39 */ 40 //@{ 41 42 #if defined(LWS_WITH_SMTP) 43 44 enum { 45 LTMI_PSMTP_V_HELO = LTMI_PROTOCOL_BASE, /* u.value */ 46 47 LTMI_PSMTP_V_LWS_SMTP_EMAIL_T, /* u.value */ 48 }; 49 50 enum { 51 LWS_SMTP_DISPOSITION_SENT, 52 LWS_SMTP_DISPOSITION_FAILED, 53 LWS_SMTP_DISPOSITION_FAILED_DESTROY 54 }; 55 56 typedef struct lws_smtp_sequencer_args { 57 const char helo[32]; 58 struct lws_vhost *vhost; 59 time_t retry_interval; 60 time_t delivery_timeout; 61 size_t email_queue_max; 62 size_t max_content_size; 63 } lws_smtp_sequencer_args_t; 64 65 typedef struct lws_smtp_sequencer lws_smtp_sequencer_t; 66 typedef struct lws_smtp_email lws_smtp_email_t; 67 68 LWS_VISIBLE LWS_EXTERN lws_smtp_sequencer_t * 69 lws_smtp_sequencer_create(const lws_smtp_sequencer_args_t *args); 70 71 LWS_VISIBLE LWS_EXTERN void 72 lws_smtp_sequencer_destroy(lws_smtp_sequencer_t *s); 73 74 typedef int (*lws_smtp_cb_t)(void *e, void *d, int disp, const void *b, size_t l); 75 typedef struct lws_smtp_email lws_smtp_email_t; 76 77 /** 78 * lws_smtpc_add_email() - Allocates and queues an email object 79 * 80 * \param s: smtp sequencer to queue on 81 * \param payload: the email payload string, with headers and terminating . 82 * \param payload_len: size in bytes of the payload string 83 * \param sender: the sender name and email 84 * \param recipient: the recipient name and email 85 * \param data: opaque user data returned in the done callback 86 * \param done: callback called when the email send succeeded or failed 87 * 88 * Allocates an email object and copies the payload, sender and recipient into 89 * it and initializes it. Returns NULL if OOM, otherwise the allocated email 90 * object. 91 * 92 * Because it copies the arguments into an allocated buffer, the original 93 * arguments can be safely destroyed after calling this. 94 * 95 * The done() callback must free the email object. It doesn't have to free any 96 * individual members. 97 */ 98 LWS_VISIBLE LWS_EXTERN int 99 lws_smtpc_add_email(lws_smtp_sequencer_t *s, const char *payload, 100 size_t payload_len, const char *sender, 101 const char *recipient, void *data, lws_smtp_cb_t done); 102 103 /** 104 * lws_smtpc_free_email() - Add email to the list of ones being sent 105 * 106 * \param e: email to queue for sending on \p c 107 * 108 * Adds an email to the linked-list of emails to send 109 */ 110 LWS_VISIBLE LWS_EXTERN int 111 lws_smtpc_free_email(lws_smtp_email_t *e); 112 113 114 #endif 115 //@} 116