Re: [newbie] Specifying SMTP from command line

2002-03-28 Thread Jim Dawson

Could you send me a copy of this or post it to a ftp or web site? I've
been looking (unsuccessfully) for such a utility for quite a while.

Thanks.

On Sat, 2002-03-23 at 16:54, Gerald Waugh wrote:
 On Friday 22 March 2002 03:32 pm, Miark wrote:
  It's a tad more involved that I had hoped, but if this is the way,
  then it's the way!
 
 
 OK, I drummed up a rough 'c' program that might help
 [gerald@gail gerald]$ ./clmail
 only 5 arguments are supported
 useage: smtpserver to from subject message
 Note: Subject and message must be enclosed in 
 
 Example:  clmail smtp.frontstreetnetworks.com [EMAIL PROTECTED] 
 [EMAIL PROTECTED] test this this is a test
 
 the first arg is the SMTP server, 2nd is TO third is FROM, 4th is SUBJECT, 
 5th is the MSG.
 
 SUBJECT and MSG must be enclosed int  
 
 copy the executable clmail to /usr/local/bin or someplace so its in your $PATH
 
 -- 
 Gerald Waugh
 http://www.frontstreetnetworks.com
 New Haven, CT, United States of America
 5:48pm up 2 days, 2:12, 2 users, load average: 0.91, 1.05, 1.07
 
 
 

 Want to buy your Pack or Services from MandrakeSoft? 
 Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Specifying SMTP from command line

2002-03-28 Thread Gerald Waugh

On Thursday 28 March 2002 10:14 pm, Jim Dawson wrote:
 Could you send me a copy of this or post it to a ftp or web site? I've
 been looking (unsuccessfully) for such a utility for quite a while.


OK , I added some error checking and it should be reasonably foolproof.
I am attaching the files   clmail   and   clmail.c
If someone wants to put these up on a ftp site, OK by me.
I don't know if the list allows attachments so they might not go through.

su -
password
cp clmail /usr/local/bin/clmail
chmod 711 /usr/local/bin/clmail
exit

entering clmail with no arguements yields:
5 arguments are supported
useage: smtpserver TO FROM subject message

Note: The subject and message must be enclosed in  if they contain 
whitespace.

-- 
Gerald Waugh Linux user # 255245
http://www.frontstreetnetworks.com
New Haven, CT, United States of America
11:49pm up 7 days, 8:14, 2 users, load average: 1.21, 1.06, 1.01


/* ==
 * clmail.c - simple smtp command line email application
 * 
 * By Gerald Waugh 
 * March 29, 2002
 * 
 * to install:
 * s u -
 * password
 * cp clmail /usr/local/bin/clmail
 * chmod 711 /usr/local/bin/clmail
 * exit
 * entering clmail with no arguements yields:
 * 5 arguments are supported
 * useage: smtpserver TO FROM subject message
 *
 * Note: The subject and message must be enclosed in  if they contain whitespace.
 *
 * === */
#include netdb.h
#include netinet/in.h
#include stdio.h
#include sys/socket.h
#include sys/types.h
#include unistd.h
#include stdlib.h
#include string.h

void die (char *s)
{
   printf(Error: %s\n,s);
}

//=
int main(int argc, char ** argv) {
struct sockaddr_in address;
struct in_addr inaddr;
struct hostent * host;
int sock, nBytes;
int buffsize = 1024;
char Buff[buffsize];

strcpy(Buff, );
//=
//== C H E C KA R G S =
//=
if (argc != 6) {
fprintf(stderr, 5 arguments are supported\n\
useage: smtpserver TO FROM \subject\ \message\\n\0);
return 1;
}

/* If the argument can be converted to an IP, do so. If not, try
   to look it up in DNS. */
if (inet_aton(argv[1], inaddr))
host = gethostbyaddr((char *) inaddr, sizeof(inaddr), AF_INET);
else
host = gethostbyname(argv[1]);

if (!host) {
/* We can't find an IP number */
herror(error looking up host);
exit(1);
}
//=
//=== C R E A T E   S O C K E T ===
//=
if ((sock = socket(PF_INET, SOCK_STREAM, 0))  0) {
die(socket);
	exit(1);
}

address.sin_family = AF_INET;
address.sin_port = htons(25);

/* Take the first IP address associated with this hostname */
memcpy(address.sin_addr, host-h_addr_list[0], sizeof(address.sin_addr));

if (connect(sock, (struct sockaddr *) address, sizeof(address)))
die(connect);

//
//== I N I T   G A T E W A Y =
//
nBytes = recv(sock, Buff, buffsize, 0);
//if(nBytes  0)
//   printf(%s\n, Buff); 
//
strcpy(Buff, HELO );
strcat(Buff, argv[1]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0); // send 'mail from' command
//printf(%s\n, Buff);

nBytes = recv(sock, Buff, buffsize, 0);
if(nBytes  0) {
	if(Buff[0] == '5') {
Buff[nBytes] = '\0'; 
	printf(Error: %s, Buff);
	exit(1);
	}
}
//
strcpy(Buff, MAIL FROM: );
strcat(Buff, argv[3]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0); // send 'mail from' command
//printf(%s\n, Buff);

nBytes = recv(sock, Buff, buffsize, 0);
if(nBytes  0) {
   if(Buff[0] == '5') {
Buff[nBytes] = '\0';
	printf(Error: %s, Buff);
   exit(1);
   }
}
//
strcpy(Buff, RCPT TO: );
strcat(Buff, argv[2]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0);  // send mail to command
//printf(%s\n, Buff);

nBytes = recv(sock, Buff, buffsize, 0);
if(nBytes  0) {
	if(Buff[0] == '5') {
Buff[nBytes] = '\0';
	printf(Error: %s, Buff);
	exit(1);
	}
}
//
strcpy(Buff, DATA\n);
send(sock, Buff, strlen(Buff), 0);  // send DATA command
//printf(%s\n, Buff);

nBytes = recv(sock, Buff, buffsize, 0);
if(nBytes  0) {
	if(Buff[0] == '5') {
Buff[nBytes] = 

Re: [newbie] Specifying SMTP from command line

2002-03-23 Thread Gerald Waugh

On Friday 22 March 2002 03:32 pm, Miark wrote:
 It's a tad more involved that I had hoped, but if this is the way,
 then it's the way!


OK, I drummed up a rough 'c' program that might help
[gerald@gail gerald]$ ./clmail
only 5 arguments are supported
useage: smtpserver to from subject message
Note: Subject and message must be enclosed in 

Example:  clmail smtp.frontstreetnetworks.com [EMAIL PROTECTED] 
[EMAIL PROTECTED] test this this is a test

the first arg is the SMTP server, 2nd is TO third is FROM, 4th is SUBJECT, 
5th is the MSG.

SUBJECT and MSG must be enclosed int  

copy the executable clmail to /usr/local/bin or someplace so its in your $PATH

-- 
Gerald Waugh
http://www.frontstreetnetworks.com
New Haven, CT, United States of America
5:48pm up 2 days, 2:12, 2 users, load average: 0.91, 1.05, 1.07



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Specifying SMTP from command line

2002-03-23 Thread Gerald Waugh

On Saturday 23 March 2002 05:54 pm, Gerald Waugh wrote:
 On Friday 22 March 2002 03:32 pm, Miark wrote:
  It's a tad more involved that I had hoped, but if this is the way,
  then it's the way!

 OK, I drummed up a rough 'c' program that might help
 [gerald@gail gerald]$ ./clmail
 only 5 arguments are supported
 useage: smtpserver to from subject message
 Note: Subject and message must be enclosed in 

 Example:  clmail smtp.frontstreetnetworks.com [EMAIL PROTECTED]
 [EMAIL PROTECTED] test this this is a test

 the first arg is the SMTP server, 2nd is TO third is FROM, 4th is SUBJECT,
 5th is the MSG.

 SUBJECT and MSG must be enclosed int 

 copy the executable clmail to /usr/local/bin or someplace so its in your
 $PATH

-- 
Gerald Waugh
http://www.frontstreetnetworks.com
New Haven, CT, United States of America
8:19pm up 2 days, 4:43, 2 users, load average: 1.54, 1.68, 1.68



clmail
Description: application/executable

/* tclient.c - simple client for TCP/IP sockets */
#include netdb.h
#include netinet/in.h
#include stdio.h
#include sys/socket.h
#include sys/types.h
#include unistd.h
#include stdlib.h
#include string.h

void die (char *s)
{
   printf(Error: %s\n,s);
}

//nclude sockutil.h  /* some utility functions */
char init_state = 0;

void printMessage(char *ptr, char type)
{
   if(init_state == 0  type == 0) {
  init_state = 1;
  printf(MsgRx: );
  while(*ptr != '(') ptr++;
   }
   else
   {
  if(!type)
 printf(MsgRx: );
  else
 printf(MsgTx: );
  while(*ptr  ' '  *ptr  'z') ptr++;
   }
   printf(%s\n, ptr);
}
//=
//== M A I N ==
//=
int main(int argc, char ** argv) {
struct sockaddr_in address;
struct in_addr inaddr;
struct hostent * host;
int sock, sock2, nBytes;
int buffsize = 1024;
char Buff[buffsize], cBuff[80];
char *iBuff, *oBuff;
char *cPtr, *iPtr, *oPtr;

iBuff = oBuff = Buff;
strcpy(Buff, );
//=
//== C H E C KA R G S =
//=
if (argc != 6) {
fprintf(stderr, only 5 arguments are supported\n\
useage: smtpserver to from subject message\n\
Note: Subject and message must be enclosed in \\\n);
return 1;
}

/* If the argument can be converted to an IP, do so. If not, try
   to look it up in DNS. */
if (inet_aton(argv[1], inaddr))
host = gethostbyaddr((char *) inaddr, sizeof(inaddr), AF_INET);
else
host = gethostbyname(argv[1]);

if (!host) {
/* We can't find an IP number */
herror(error looking up host);
exit(1);
}
//=
//=== C R E A T E   S O C K E T ===
//=
if ((sock = socket(PF_INET, SOCK_STREAM, 0))  0)
die(socket);

address.sin_family = AF_INET;
address.sin_port = htons(25);

/* Take the first IP address associated with this hostname */
memcpy(address.sin_addr, host-h_addr_list[0], sizeof(address.sin_addr));

if (connect(sock, (struct sockaddr *) address, sizeof(address)))
die(connect);
//else
//printf(\n\nThe connection was accepted by the server %s\n, argv[1]);


//dd
//== I N I T   G A T E W A Y =
//
nBytes = recv(sock, Buff, buffsize, 0);
//if(nBytes  0)
//   printf(%s\n, Buff); 

strcpy(Buff, MAIL FROM: );
strcat(Buff, argv[3]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0); // send 'mail from' command
//printf(%s\n, Buff);

nBytes = recv(sock, Buff, buffsize, 0);
//if(nBytes  0)
//   printf(Buff, 0);

strcpy(Buff, RCPT TO: );
strcat(Buff, argv[2]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0);  // send mail to command
//printf(%s\n, Buff);

//nBytes = recv(sock, Buff, buffsize, 0);
//if(nBytes  0)
//   printf(%s\n, Buff);

strcpy(Buff, DATA\n);
send(sock, Buff, strlen(Buff), 0);  // send DATA command
//printf(%s\n, Buff);

//nBytes = recv(sock, Buff, buffsize, 0);
//if(nBytes  0)
//   printf(%s\n, Buff);

strcpy(Buff, To: );
strcat(Buff, argv[2]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0);  // send To command
//printf(%s\n, Buff);

strcpy(Buff, Subject: );
strcat(Buff, argv[4]);
strcat(Buff, \n);
send(sock, Buff, strlen(Buff), 0);  // send mesage 
//printf(%s\n, Buff);

strcat(Buff, argv[5]);
strcat(Buff, \r\n);
send(sock, Buff, strlen(Buff), 0);  // send mesage
		
strcpy(Buff, \r\n.\r\n);
send(sock, Buff, strlen(Buff), 0);  // send END DATA '.' command
//  

Re: [newbie] Specifying SMTP from command line

2002-03-23 Thread Gerald Waugh

On Saturday 23 March 2002 05:54 pm, Gerald Waugh wrote:
 On Friday 22 March 2002 03:32 pm, Miark wrote:
  It's a tad more involved that I had hoped, but if this is the way,
  then it's the way!

 OK, I drummed up a rough 'c' program that might help
 [gerald@gail gerald]$ ./clmail
 only 5 arguments are supported
 useage: smtpserver to from subject message
 Note: Subject and message must be enclosed in 

 Example:  clmail smtp.frontstreetnetworks.com [EMAIL PROTECTED]
 [EMAIL PROTECTED] test this this is a test

 the first arg is the SMTP server, 2nd is TO third is FROM, 4th is SUBJECT,
 5th is the MSG.

 SUBJECT and MSG must be enclosed int 

 copy the executable clmail to /usr/local/bin or someplace so its in your
 $PATH

-- 
Gerald Waugh
http://www.frontstreetnetworks.com
New Haven, CT, United States of America
11:06pm up 2 days, 7:30, 2 users, load average: 1.60, 1.68, 1.63



clmail
Description: smtp client

Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



[newbie] Specifying SMTP from command line

2002-03-21 Thread Miark

Is there a way I can send e-mail from the command line and
specify which SMTP server to use (e.g. my company's server 
versus my ISP)?

Miark



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [newbie] Specifying SMTP from command line

2002-03-21 Thread Gerald Waugh

On Thursday 21 March 2002 11:54 pm, Miark wrote:
 Is there a way I can send e-mail from the command line and
 specify which SMTP server to use (e.g. my company's server
 versus my ISP)?

 Miark
S is what you enter
R is the mail servers response.

S telnet isp.add.re.ss 25
R Trying 216.175.178.41...
 Connected to domain.com (ip.add.re.ss).
 Escape character is '^]'. 
 220 domain.comESMTP Sendmail 8.9.3; Fri, 22 Mar 2002 00:39:05 -0500
 NO UCE  C=CT L=US
S MAIL FROM: [EMAIL PROTECTED]
R 250 [EMAIL PROTECTED] Sender ok
S RCPT TO: [EMAIL PROTECTED]
R 250 [EMAIL PROTECTED] Recipient ok
S DATA
R 354 Enter mail, end with . on a line by itself
S To: Gerald
 From: Jerry
 Subject: Junk Mail
 X-extra: Extra lines in the header for those who want them
   |Junk mail - don't you just love it?
   J   (ending is last line with only '.')
.
R 250 AAA18093 Message accepted for delivery
S quit
R  221 domain.com closing connection
R  Connection closed by foreign host.

-- 
Gerald Waugh
http://www.frontstreetnetworks.com
New Haven, CT United States of America
uptime 12:26am up 8:50, 2 users, load average: 0.00, 0.00, 0.00



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com