/******************************************************************************
SMTP.C
Copyright (C) 2001, ZWorld

Demonstates the use of the DM_SMTP.LIB library for sending e-mail messages
from a target processor with a DeviceMate.

The program will send out a single test message through an attached 
DeviceMate that is providing the basic TCP/IP service. The following macros
in the program should be changed below to properly send the test message.

MY_SMTP_SERVER
MY_SMTP_DOMAIN 
FROM
TO

******************************************************************************/


/* Request use of SMTP email services */
#define USE_TC_SMTP

/*
 * Uncomment this line if this program will be loaded over ethernet. This will
 * force the DevMate communication to use serial port A, re-using the programming
 * link that was used to download the program.
 */
//#define USE_TC_LOADER

#ifdef CC_VER
	/* Dynamic C */
	#memmap xmem
	#use "tc_conf.lib"
#else
	/* Non-Rabbit */
	#include "tc_conf.h"
	#include <stdio.h>	
#endif


#define MY_SMTP_SERVER	"mail.somewhere.org"
#define MY_SMTP_DOMAIN	"somewhere.org"
#define FROM				"DevMate@somewhere.org"
#define TO					"nobody@nowhere.org,everybody@everywhere.org"
#define SUBJECT			"test mail"

int main()
{
	char message[256];

	devmate_init();

	/* SMTP uses TCP/IP, hence the following init call is required. */
	printf("devmate_sock_init: %d\n",
	  devmate_sock_init(NULL, NULL, NULL, NULL, NULL, NULL)
	  );

	/* Set the server and our domain */
	devmate_smtp_setserver(MY_SMTP_SERVER);
	devmate_smtp_setdomain(MY_SMTP_DOMAIN);

	/* Create a message */
	strcpy(message,
	  "Warning! Warning!\r\nTemperature in the computer room over 40 deg C!"
	  );
	
	devmate_smtp_sendmail(TO, FROM, SUBJECT, message);
		
	while (devmate_smtp_mailtick() == DM_SMTP_PENDING);

	if (devmate_smtp_status() == DM_SMTP_SUCCESS)
		printf("Message sent\n");
	else
		printf("Error sending message\n");

	/* Sit in endless loop until reset. */
	while (1)
		devmate_tick();
}
