72 |
*/ |
*/ |
73 |
|
|
74 |
|
|
75 |
/* ------------------------------------------------------- Private variables */ |
/* ------------------------------------------------------------- Definitions */ |
76 |
|
|
77 |
|
|
78 |
typedef struct { |
typedef struct { |
79 |
|
char *now; |
80 |
Socket_T socket; |
Socket_T socket; |
81 |
sigjmp_buf error; |
sigjmp_buf error; |
82 |
const char *server; |
const char *server; |
83 |
|
char localhost[STRLEN]; |
84 |
} SendMail_T; |
} SendMail_T; |
85 |
|
|
86 |
|
|
102 |
|
|
103 |
Mail_T m; |
Mail_T m; |
104 |
SendMail_T S; |
SendMail_T S; |
|
char localhost[STRLEN]; |
|
|
char *now = get_RFC822date(NULL); |
|
105 |
|
|
106 |
ASSERT(mail); |
ASSERT(mail); |
107 |
|
|
108 |
S.server= Run.mailserver?Run.mailserver:LOCALHOST; |
S.server= Run.mailserver?Run.mailserver:LOCALHOST; |
109 |
|
|
110 |
if(gethostname(localhost, sizeof(localhost)) < 0) { |
if(gethostname(S.localhost, sizeof(S.localhost)) < 0) { |
111 |
snprintf(localhost, STRLEN, LOCALHOST); |
snprintf(S.localhost, STRLEN, LOCALHOST); |
112 |
} |
} |
113 |
|
|
114 |
|
S.now= get_RFC822date(NULL); |
115 |
|
|
116 |
S.socket= socket_new(S.server, SMTP_PORT, SOCKET_TCP, FALSE); |
S.socket= socket_new(S.server, SMTP_PORT, SOCKET_TCP, FALSE); |
117 |
if(!S.socket) { |
if(!S.socket) { |
118 |
log("Cannot open a connection to the mailserver '%s' -- %s\n", |
log("Cannot open a connection to the mailserver '%s' -- %s\n", |
125 |
} |
} |
126 |
|
|
127 |
do_status(&S); |
do_status(&S); |
128 |
do_send(&S, "HELO %s\r\n", localhost); |
do_send(&S, "HELO %s\r\n", S.localhost); |
129 |
do_status(&S); |
do_status(&S); |
130 |
|
|
131 |
for(m= mail; m; m= m->next) { |
for(m= mail; m; m= m->next) { |
139 |
do_send(&S, "From: %s\r\n", m->from); |
do_send(&S, "From: %s\r\n", m->from); |
140 |
do_send(&S, "To: %s\r\n", m->to); |
do_send(&S, "To: %s\r\n", m->to); |
141 |
do_send(&S, "Subject: %s\r\n", m->subject); |
do_send(&S, "Subject: %s\r\n", m->subject); |
142 |
do_send(&S, "Date: %s\r\n", now); |
do_send(&S, "Date: %s\r\n", S.now); |
143 |
do_send(&S, "X-Mailer: %s %s\r\n", prog, VERSION); |
do_send(&S, "X-Mailer: %s %s\r\n", prog, VERSION); |
144 |
do_send(&S, "Mime-Version: 1.0\r\n"); |
do_send(&S, "Mime-Version: 1.0\r\n"); |
145 |
do_send(&S, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"); |
do_send(&S, "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"); |
157 |
do_send(&S, "QUIT\r\n"); |
do_send(&S, "QUIT\r\n"); |
158 |
|
|
159 |
exit: |
exit: |
160 |
free(now); |
free(S.now); |
161 |
if(S.socket) { |
if(S.socket) { |
162 |
socket_free(&S.socket); |
socket_free(&S.socket); |
163 |
} |
} |