| Description | The smtp_connect function starts the SMTP client on the TCPnet system. This causes the SMTP client to then start an SMTP session by connecting to an SMTP server on the TCP port specified in the function argument. The argument ipadr points to an array of 4 bytes containing the dotted-decimal notation of the IP address of the SMTP server to connect to. The argument cbfunc points to a function that the SMTP client running on TCPnet calls when the SMTP session ends. The cbfunc is an event callback function that uses the event argument of the cbfunc function to signal one of the following SMTP events: | Event | Description |
|---|
| SMTP_EVT_SUCCESS | The email has been successfully sent. | | SMTP_EVT_TIMEOUT | SMTP Server response has timed out, and hence the SMTP client has aborted the operation. The email has not been sent. | | SMTP_EVT_ERROR | Protocol error occurred when sending the email. The email has not been sent. |
The smtp_connect function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - The standard SMTP port is TCP port 25.
- Your application, running on TCPnet, can call the smtp_connect function to connect to an SMTP server to send emails.
|
| Example |
static void smtp_cback (U8 event);
void send_email (void) {
U8 smtpip[4] = {192,168,2,253};
if (smtp_connect (smtpip, 25, smtp_cback) == 0) {
printf("E-mail not sent, SMTP Client not ready.\n");
}
else {
printf("SMTP Client started.\n");
}
}
static void smtp_cback (U8 event) {
switch (event) {
case SMTP_EVT_SUCCESS:
printf ("Email successfully sent\n");
break;
case SMTP_EVT_TIMEOUT:
/* Timeout, try again. */
printf ("Mail Server timeout.\n");
break;
case SMTP_EVT_ERROR:
/* Error, try again. */
printf ("Error sending email.\n");
break;
}
}
|