probably junk file, use smail.c!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!

#include <stdlib.h>
#include <string.h>
#include "tcplib.h"
#include <stdio.h>

#include "defines.h"

typedef struct IMAIL {Chan *c;} Imail;

int imail_new(Imail **im);
int imail_rcpt(Imail *out,char *from);
int imail_printf(Imail *out,char *format,...);
int imail_close(Imail **out);

/*
Example of use:

  imail_new(&m);
  imail_rcpt(m,"bob@netwin.co.nz");
  imail_printf("Body of message\n");
  imail_printf("\n");
  imail_send(m,envfrom,from,to,cc,bcc,subject);
  imail_free(&m);

*/

int imail_new(Imail **im)
{
	Imail *m;
	char reason[BFSZ];
	m = calloc(sizeof(Imail),1);
	*im = m;
	msg_new(&m->m);
	if (!msg_open(m->m,reason)) {
		emsg("Msg_open failed (%s)\n",reason);
		return FALSE;
	}
	m->m->fromip = strdup("localhost");
	m->m->from = strdup("<>");
	return TRUE;
}
int imail_rcpt(Imail *out,char *from)
{
	char reason[BFSZ];
//	if (!msg_rcpt_add(out->m,from,reason)) {

	imsg("imail: rcpt (%s)\n",from);
	if (!msg_rcpt_new(out->m, from, NULL, TRUE, reason)) {
		imsg("Imail rcpt failed %s %s\n",from,reason);
	}
	return TRUE;
}
int imail_printf(Imail *out,char *arg_list,...)
{
        va_list arg_ptr;
        char *format;
 	char output[2000];

        va_start(arg_ptr, arg_list);
        format = (char *)  arg_list;
        vsnprintf(output,1000, format, arg_ptr); output[1000-1] = 0;
	msg_write(out->m,output,strlen(output));
	return TRUE;
}
extern int isimail;
int imail_close(Imail **out)
{
	char reason[BFSZ];
	Imail *o= *out;
//Msgin *m = o->m;
//if (m->f!=NULL) fclose(m->f);
//m->f = NULL;
//abort();
isimail = TRUE;
	if (!msg_submit(o->m,reason)) {
		msg_delete(m);
		imsg("imail_close (%s)\n",reason);
	}
	msg_free(&o->m);
	free(*out);
	*out = NULL;
	return TRUE;
}



int read_line(Chan *MyChannel){
	char Buffer[BFSZ];
//	int n;
	tcp_readline(MyChannel, Buffer, BFSZ-2);
	//if (n>=0 && n<=BFSZ)
//		Buffer[n] = 0;
	imsg("read: {%s}\n", Buffer);
	if (*Buffer == '5')
		return FALSE;
	return TRUE;
}

int send_email(char *smtp_server,	char *fromname, char *fromemail,
									char *toname, char *toemail, char *subject, char *body){
	char *Cr = "\r\n";
	Chan *MyChannel = NULL;

	tcp_init(emsg);
	tcp_new(  &MyChannel);
	tcp_open(  MyChannel, smtp_server, 2525, NULL);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "HELO TestMailProgram%s", Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "MAIL FROM: <%s>%s", fromemail, Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "RCPT TO: <%s>%s", toemail, Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "DATA%s", Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "To: \"%s\" <%s>%s", toname, toemail, Cr);
	tcp_printf(MyChannel, "From: \"%s\" <%s>%s", fromname, fromemail, Cr);
	tcp_printf(MyChannel, "Subject: %s%s", subject, Cr);
	tcp_printf(MyChannel, "%s", Cr);
	tcp_printf(MyChannel, "%s%s.%s", body, Cr, Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_printf(MyChannel, "QUIT%s", Cr);
	if (!read_line( MyChannel)) return FALSE;
	tcp_release(MyChannel);
	tcp_free(& MyChannel);
	return TRUE;
}


int main(int argc, char *argv[]){
	int result;
	result = emsg_open("app5log.txt");
	//printf("emsg result is %d\n", result);

	if (argc==2){
		result = send_email( "10.0.0.10",
							"Jesse sender",
							"jesse@netwin.co.nz",
							"Jesse recipient",
							argv[1],
							"This is a test message",
							"Hi,\n"
							"Just testing.....\n"
							"bye 4 now.\n");
	}else{
		result = send_email( "10.0.0.10",
							"Jesse sender",
							"jesse@netwin.co.nz",
							"Jesse recipient",
							"jesse@netwin.co.nz",
							"This is a test message",
							"Hi,\n"
							"Just testing.....\n"
							"bye 4 now.\n");
	}

	if (result){
		//printf("The email was sent to the smtp server correctly.\n");
		imsg("The email was sent to the smtp server correctly.\n");
	}else{
		//printf("There was a problem sending the email.\n");
		emsg("There was a problem sending the email.\n");
	}
	emsg_close();
	return 0;
}
