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 K A 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
// printf("%s\n", Buff);
nBytes = recv(sock, Buff, buffsize, 0);
// if(nBytes > 0)
// printf("%s\n", Buff);
strcpy(Buff, "QUIT\n");
send(sock, Buff, strlen(Buff), 0); // send quit command
// printf("%s\n", Buff);
nBytes = recv(sock, Buff, buffsize, 0);
// if(nBytes > 0)
// printf("%s\n", Buff);
printf("message sent\n");
close(sock);
return 0;
}
Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
