performs the send SMTP message state machine. A small buffer for incoming messages is allocated from heap and should be freed any time this function is left. The SMTP gateway is hard-coded in socket_open() function. To make this function more flexible the gateway address should be passed as a parameter.
More information on the exact specification of SMTP and the meanings of the commands and responses can be found in RFC821 at http://www.ietf.org.
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#pragma CODE_SECTION(get_reply_code , ".commontext")
#pragma CODE_SECTION(send_mail , ".commontext")
#pragma CODE_SECTION(wait_for_link , ".commontext")
#ifdef __cplusplus
}
#endif
#define MAX_DATA 512
#define SMTPGATEWAY "deepthought"
#define SOURCE_EMAIL_ADDRESS "dsp@dsignt.de"
#define SOURCE_PASS "testpass"
#define DEST_EMAIL_ADDRESS "claus.hermbusche@dsignt.de"
typedef enum
{
typedef enum {
#define SMTP_SERVICE_READY UINT32_C(220)
#define SMTP_SERVICE_CLOSING UINT32_C(221)
#define SMTP_REQUEST_OK UINT32_C(250)
#define SMTP_AUTHENTICATED UINT32_C(235)
#define SMTP_START_MAIL UINT32_C(354)
#define UTC_PRINTF " Current UTC time: "VT100_BLUE"%s\r"VT100_DEFAULT
static char auth_msg[] = {
"AUTH LOGIN\r\n"};
static char sub_msg[] = {
"Subject: Test mail from DSP\r\n"};
static char cont_msg[] = {
"Content-Type: text/plain\r\n"};
static char prio_msg[] = {
"Priority: Urgent\r\n\r\n"};
static char endmail[] = {
"\r\n.\r\n"};
"%s started work at %s\r\n",
"%s is alive at %s\r\n" ,
"%s stopped work at %s\r\n",
""
};
" sending start mail ",
" sending alive mail ",
" sending stop mail ",
" SMTP test finished successfully,\r\n entering idle network processing\r\n"
};
{
{
}
{
{
ret = net_recv_event_handler (mail,
NULL);
{
}
}
}
mail_data[3] = 0;
#if (defined(_TMS320C6X) )
return (atoi (mail_data));
#else
return (atol (mail_data));
#endif
}
{
SOCKET *mail;
char *mail_data;
u_int8_t in[3], out[4];
int i;
char *p, *t;
mail_data = (
char *) malloc (
MAX_DATA *
sizeof(
char));
{
return (f_result);
}
587,
{
free (mail_data);
return (f_result);
}
for (;;)
{
{
free (mail_data);
}
}
{
switch ( ms )
{
break;
{
}
else
{
}
break;
{
}
else
{
}
break;
{
while ( (*p & 0xff) != 0)
{
for ( i=0;i<3 ;i++ )
{
if (*p & 0xff)
{
in[i] = (*p++) & 0xff;
len++;
}
else
{
in[i] = 0;
}
}
if (len)
{
*t++ = out[0] & 0xff;
*t++ = out[1] & 0xff;
*t++ = out[2] & 0xff;
*t++ = out[3] & 0xff;
}
}
*t++ = '\r';
*t++ = '\n';
*t++ = 0;
}
else
{
}
break;
{
while ( (*p & 0xff) != 0)
{
for ( i=0;i<3 ;i++ )
{
if (*p & 0xff)
{
in[i] = (*p++) & 0xff;
len++;
}
else
{
in[i] = 0;
}
}
if (len)
{
*t++ = out[0] & 0xff;
*t++ = out[1] & 0xff;
*t++ = out[2] & 0xff;
*t++ = out[3] & 0xff;
}
}
*t++ = '\r';
*t++ = '\n';
*t++ = 0;
}
else
{
}
break;
{
}
else
{
}
break;
{
}
else
{
}
break;
{
}
else
{
}
break;
{
}
else
{
}
break;
{
{
}
}
else
{
}
break;
}
}
free (mail_data);
return (f_result);
}
{
{
return (1);
}
return (0);
}
#pragma CODE_SECTION(main , ".commontext");
{
int i=0;
struct tm *local_time;
char *message;
CPrintf (
" *** timer %d mapped to CPU int %d ***\r\n",
{
}
CPuts (
" network startup time [sec]: ");
"%"PRId32".%03"PRId32"\r\n"
while (ml)
{
switch (ml)
{
break;
{
}
break;
{
}
else
{
}
break;
if (i == 2)
{
i++;
}
if (i < 2)
{
{
i++;
}
}
break;
}
}
free (message);
return (0);
}