| version 1.2, 2002/09/30 07:55:48 |
version 1.3, 2002/10/01 09:49:10 |
| Line 40 unsigned long __smtpTimeout = 30; |
|
| Line 40 unsigned long __smtpTimeout = 30; |
|
| unsigned char __smtpTimedOut = 0; /* 0==FALSE 1==TRUE */ |
unsigned char __smtpTimedOut = 0; /* 0==FALSE 1==TRUE */ |
| |
|
| #define __SMTP_ALARM_SET \ |
#define __SMTP_ALARM_SET \ |
| signal(SIGALRM, (void *) smtp_alarm); \ |
signal(SIGALRM, smtp_alarm); \ |
| (void) alarm(__smtpTimeout); |
(void) alarm(__smtpTimeout); |
| #define __SMTP_ALARM_CLEAR \ |
#define __SMTP_ALARM_CLEAR \ |
| signal(SIGALRM, SIG_DFL); \ |
signal(SIGALRM, SIG_DFL); \ |
| (void) alarm(0); |
(void) alarm(0); |
| |
|
| int smtp_clear_buf(int nSocket); |
int smtp_clear_buf(int nSocket); |
| void *smtp_alarm(int unused); |
void smtp_alarm(int unused); |
| |
|
| int smtp_connect(const char* zServer, int nPort) |
int smtp_connect(const char* zServer, int nPort) |
| { |
{ |
| Line 491 int smtp_clear_buf(int nSocket) |
|
| Line 491 int smtp_clear_buf(int nSocket) |
|
| return(-1); |
return(-1); |
| } |
} |
| |
|
| void *smtp_alarm(int unused) |
void smtp_alarm(int unused) |
| /* Callback function for alarm() */ |
/* Callback function for alarm() */ |
| { |
{ |
| #ifdef __SMTP_DEBUG |
#ifdef __SMTP_DEBUG |
| Line 499 void *smtp_alarm(int unused) |
|
| Line 499 void *smtp_alarm(int unused) |
|
| #endif |
#endif |
| |
|
| __smtpTimedOut=1; |
__smtpTimedOut=1; |
| return NULL; |
return; |
| } |
} |
| |
|
| #if defined(SELF) || defined(SELFTEST) || defined(SELF_SMTP) |
#if defined(SELF) || defined(SELFTEST) || defined(SELF_SMTP) |
| |
|
| #include <stdio.h> |
#include <stdio.h> |
| |
|
| int main(void) |
int main(int argc, char **argv) |
| { |
{ |
| /* int nReturnCode=0; */ /* Return code from libsmtp */ |
register int port = SMTP_PORT; |
| |
char *server = "localhost"; |
| |
|
| char message[] = |
char message[] = |
| "From: frodo@bagend.com\r\n" |
"From: frodo@bagend.com\r\n" |
| "To: fred@foo.com, jane@baz.org\r\n" |
"To: fred@foo.com, jane@baz.org\r\n" |
| "Subject: Libsmtp example\r\n\r\n" |
"Subject: Libsmtp example\r\n\r\n" |
| "This is a message to show libsmtp in action\r\n"; |
"This is a message to show libsmtp in action\r\n"; |
| |
|
| |
if (argc < 2) { |
| |
fprintf(stderr, "Usage: %s <RCPT_TO_address> [ <smpt_server> [ <port> ]]\n", argv[0]); |
| |
return 1; |
| |
} |
| |
if (argc > 2) { |
| |
server = argv[2]; |
| |
} |
| |
if (argc > 3) { |
| |
port = atoi(argv[3]); |
| |
if (port == 0) |
| |
port = SMTP_PORT; |
| |
} |
| |
|
| /* Obviously you can build your message dynamically. This message does not |
/* Obviously you can build your message dynamically. This message does not |
| include all the headers required by RFC2822, only the bare minimum */ |
include all the headers required by RFC2822, only the bare minimum */ |
| |
|
| printf("Connecting to server\n"); |
printf("Connecting to server\n"); |
| if(smtp_connect("maxim.platon.sk", 25)<0) |
if(smtp_connect(server, port)<0) |
| { |
{ |
| printf("Failed to connect to server!\n"); |
printf("Failed to connect to server!\n"); |
| return(1); |
return(1); |
|
|
| |
|
| printf("Connected\nSending mail\n"); |
printf("Connected\nSending mail\n"); |
| |
|
| if (smtp_sendmail("nepto@maxim.platon.sk", |
if (smtp_sendmail(argv[1], |
| "radka@maxim.platon.sk", message) < 0) { |
"user@localhost", message) < 0) { |
| printf("Failed to send mail\n"); |
printf("Failed to send mail\n"); |
| /* Attempt to disconnect from the server */ |
/* Attempt to disconnect from the server */ |
| smtp_disconnect(); |
smtp_disconnect(); |