mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-08 17:13:56 +00:00
Improved email sending
SVN revision: 308
This commit is contained in:
parent
f6ad81f22b
commit
4ea4cf95c9
@ -1,3 +1,9 @@
|
|||||||
|
Version 2.2.5, released December 12th, 2002
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
- Improved speed for sending many email notifications
|
||||||
|
- Added "Omit email to" option
|
||||||
|
|
||||||
Version 2.2.4, released December 12th, 2002
|
Version 2.2.4, released December 12th, 2002
|
||||||
===========================================
|
===========================================
|
||||||
|
|
||||||
|
|||||||
@ -830,6 +830,8 @@ individual logbook sections, one has to log in to each logbook separately.<p>
|
|||||||
<LI><b><code>Email <attribute> <value> = <list></code></b>
|
<LI><b><code>Email <attribute> <value> = <list></code></b>
|
||||||
<LI><b><code>Use Email Subject = <string></code></b>
|
<LI><b><code>Use Email Subject = <string></code></b>
|
||||||
<LI><b><code>Use Email From = <string></code></b>
|
<LI><b><code>Use Email From = <string></code></b>
|
||||||
|
<LI><b><code>Omit Email To = 0|1</code></b>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
To send email automatically when new entries are created in a logbook, a <b><code>SMTP host =
|
To send email automatically when new entries are created in a logbook, a <b><code>SMTP host =
|
||||||
@ -852,7 +854,10 @@ used as the email subject. The text can contain <b><code>$<attribute>
|
|||||||
</code></b>statements which are substituted with the current value of that
|
</code></b>statements which are substituted with the current value of that
|
||||||
attribute. For a full list of possible substitutions, see the
|
attribute. For a full list of possible substitutions, see the
|
||||||
"<I>Subst <attribute></I>" option. The option <b><code>Use Email From = <string>
|
"<I>Subst <attribute></I>" option. The option <b><code>Use Email From = <string>
|
||||||
</code></b> is used for the "<I>from</I>" field in the email.
|
</code></b> is used for the "<I>from</I>" field in the email. If the flag <b><code>
|
||||||
|
Omit Email To</b></code> is set to <b>1</b>, the <i>To:</i> field in the email is
|
||||||
|
left empty insted set to the real email address of the recipients. This can
|
||||||
|
be useful if one recipient should not see the email addresses of the other recipients.
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<a name="flags"><hr>
|
<a name="flags"><hr>
|
||||||
|
|||||||
100
elogd.c
100
elogd.c
@ -6,6 +6,9 @@
|
|||||||
Contents: Web server program for Electronic Logbook ELOG
|
Contents: Web server program for Electronic Logbook ELOG
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 2.115 2002/12/13 12:07:01 midas
|
||||||
|
Improved email sending
|
||||||
|
|
||||||
Revision 2.114 2002/12/12 13:25:59 midas
|
Revision 2.114 2002/12/12 13:25:59 midas
|
||||||
Make active logbook tab also a link
|
Make active logbook tab also a link
|
||||||
|
|
||||||
@ -446,7 +449,7 @@
|
|||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
|
||||||
/* Version of ELOG */
|
/* Version of ELOG */
|
||||||
#define VERSION "2.2.4"
|
#define VERSION "2.2.5"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -1014,15 +1017,16 @@ struct timeval timeout;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT sendmail(char *smtp_host, char *from, char *to, char *subject, char *text)
|
INT sendmail(char *smtp_host, char *from, char *to, char *subject, char *text, BOOL email_to)
|
||||||
{
|
{
|
||||||
struct sockaddr_in bind_addr;
|
struct sockaddr_in bind_addr;
|
||||||
struct hostent *phe;
|
struct hostent *phe;
|
||||||
int s, offset;
|
int i, n, s, offset;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
char str[TEXT_SIZE+1000];
|
char str[TEXT_SIZE+1000];
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm *ts;
|
struct tm *ts;
|
||||||
|
char list[1024][NAME_LENGTH];
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("\n\nEmail from %s to %s, SMTP host %s:\n", from, to, smtp_host);
|
printf("\n\nEmail from %s to %s, SMTP host %s:\n", from, to, smtp_host);
|
||||||
@ -1071,11 +1075,17 @@ struct tm *ts;
|
|||||||
recv_string(s, str, sizeof(str), 3000);
|
recv_string(s, str, sizeof(str), 3000);
|
||||||
if (verbose) puts(str);
|
if (verbose) puts(str);
|
||||||
|
|
||||||
snprintf(str, sizeof(str) - 1, "RCPT TO: <%s>\r\n", to);
|
/* break recipients into list */
|
||||||
send(s, str, strlen(str), 0);
|
n = strbreak(to, list, 1024);
|
||||||
if (verbose) puts(str);
|
|
||||||
recv_string(s, str, sizeof(str), 3000);
|
for (i=0 ; i<n ; i++)
|
||||||
if (verbose) puts(str);
|
{
|
||||||
|
snprintf(str, sizeof(str) - 1, "RCPT TO: <%s>\r\n", list[i]);
|
||||||
|
send(s, str, strlen(str), 0);
|
||||||
|
if (verbose) puts(str);
|
||||||
|
recv_string(s, str, sizeof(str), 3000);
|
||||||
|
if (verbose) puts(str);
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(str, sizeof(str) - 1, "DATA\r\n");
|
snprintf(str, sizeof(str) - 1, "DATA\r\n");
|
||||||
send(s, str, strlen(str), 0);
|
send(s, str, strlen(str), 0);
|
||||||
@ -1083,7 +1093,18 @@ struct tm *ts;
|
|||||||
recv_string(s, str, sizeof(str), 3000);
|
recv_string(s, str, sizeof(str), 3000);
|
||||||
if (verbose) puts(str);
|
if (verbose) puts(str);
|
||||||
|
|
||||||
snprintf(str, sizeof(str) - 1, "To: %s\r\nFrom: %s\r\nSubject: %s\r\n", to, from, subject);
|
if (email_to)
|
||||||
|
{
|
||||||
|
snprintf(str, sizeof(str) - 1, "To: %s\r\n", to);
|
||||||
|
send(s, str, strlen(str), 0);
|
||||||
|
if (verbose) puts(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(str, sizeof(str) - 1, "From: %s\r\nSubject: %s\r\n", from, subject);
|
||||||
|
send(s, str, strlen(str), 0);
|
||||||
|
if (verbose) puts(str);
|
||||||
|
|
||||||
|
snprintf(str, sizeof(str) - 1, "From: %s\r\nSubject: %s\r\n", from, subject);
|
||||||
send(s, str, strlen(str), 0);
|
send(s, str, strlen(str), 0);
|
||||||
if (verbose) puts(str);
|
if (verbose) puts(str);
|
||||||
|
|
||||||
@ -5500,7 +5521,7 @@ int i, fh, size, self_register;
|
|||||||
sprintf(url+strlen(url), "?cmd=Login&unm=%s", getparam("new_user_name"));
|
sprintf(url+strlen(url), "?cmd=Login&unm=%s", getparam("new_user_name"));
|
||||||
sprintf(mail_text+strlen(mail_text), "%s %s\r\n", loc("You can access it at"), url);
|
sprintf(mail_text+strlen(mail_text), "%s %s\r\n", loc("You can access it at"), url);
|
||||||
|
|
||||||
sendmail(smtp_host, mail_from, getparam("new_user_email"), subject, mail_text);
|
sendmail(smtp_host, mail_from, getparam("new_user_email"), subject, mail_text, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5555,7 +5576,7 @@ int i, fh, size, self_register;
|
|||||||
loc("Logbook"), url, getparam("new_user_name"), pl);
|
loc("Logbook"), url, getparam("new_user_name"), pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendmail(smtp_host, mail_from, email_addr, subject, mail_text);
|
sendmail(smtp_host, mail_from, email_addr, subject, mail_text, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
pl = strtok(NULL, " ,");
|
pl = strtok(NULL, " ,");
|
||||||
@ -8236,11 +8257,12 @@ LOGBOOK *lbs_cur;
|
|||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int compose_mail(LOGBOOK *lbs, char *mail_to, int message_id, char attrib[MAX_N_ATTR][NAME_LENGTH],
|
int compose_mail(LOGBOOK *lbs, char *mail_to, int message_id, char attrib[MAX_N_ATTR][NAME_LENGTH],
|
||||||
char *mail_param, int *n_mail, int old_mail)
|
char *mail_param, int old_mail)
|
||||||
{
|
{
|
||||||
int j;
|
int i, j, n;
|
||||||
char str[256], mail_from[256], mail_text[TEXT_SIZE+1000], smtp_host[256], subject[256];
|
char str[256], mail_from[256], mail_text[TEXT_SIZE+1000], smtp_host[256], subject[256];
|
||||||
char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
||||||
|
char list[MAX_PARAM][NAME_LENGTH];
|
||||||
|
|
||||||
if (!getcfg("global", "SMTP host", smtp_host))
|
if (!getcfg("global", "SMTP host", smtp_host))
|
||||||
{
|
{
|
||||||
@ -8318,7 +8340,10 @@ char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
|||||||
getparam("text"));
|
getparam("text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
sendmail(smtp_host, mail_from, mail_to, subject, mail_text);
|
if (getcfg(lbs->name, "Omit Email to", str) && atoi(str) == 1)
|
||||||
|
sendmail(smtp_host, mail_from, mail_to, subject, mail_text, FALSE);
|
||||||
|
else
|
||||||
|
sendmail(smtp_host, mail_from, mail_to, subject, mail_text, TRUE);
|
||||||
|
|
||||||
if (!getcfg(lbs->name, "Display email recipients", str) ||
|
if (!getcfg(lbs->name, "Display email recipients", str) ||
|
||||||
atoi(str) == 1)
|
atoi(str) == 1)
|
||||||
@ -8327,7 +8352,14 @@ char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
|||||||
strcpy(mail_param, "?");
|
strcpy(mail_param, "?");
|
||||||
else
|
else
|
||||||
strcat(mail_param, "&");
|
strcat(mail_param, "&");
|
||||||
sprintf(mail_param+strlen(mail_param), "mail%d=%s", (*n_mail)++, mail_to);
|
|
||||||
|
n = strbreak(mail_to, list, MAX_PARAM);
|
||||||
|
for (i=0 ; i<n && i<MAX_PARAM ; i++)
|
||||||
|
{
|
||||||
|
sprintf(mail_param+strlen(mail_param), "mail%d=%s", i, list[i]);
|
||||||
|
if (i<n-1)
|
||||||
|
strcat(mail_param, "&");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -8341,10 +8373,10 @@ char str[256], file_name[256], error[1000], date[80],
|
|||||||
mail_list[MAX_N_LIST][NAME_LENGTH], list[10000],
|
mail_list[MAX_N_LIST][NAME_LENGTH], list[10000],
|
||||||
attrib[MAX_N_ATTR][NAME_LENGTH], subst_str[256], in_reply_to[80],
|
attrib[MAX_N_ATTR][NAME_LENGTH], subst_str[256], in_reply_to[80],
|
||||||
reply_to[256], user[256], user_email[256], email_notify[256];
|
reply_to[256], user[256], user_email[256], email_notify[256];
|
||||||
char *buffer[MAX_ATTACHMENTS], mail_param[1000];
|
char *buffer[MAX_ATTACHMENTS], mail_param[1000], *mail_to;
|
||||||
char att_file[MAX_ATTACHMENTS][256];
|
char att_file[MAX_ATTACHMENTS][256];
|
||||||
char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH];
|
||||||
int i, j, n, missing, first, index, n_mail, suppress, message_id, resubmit_orig;
|
int i, j, n, missing, first, index, suppress, message_id, resubmit_orig, mail_to_size;
|
||||||
|
|
||||||
/* check for required attributs */
|
/* check for required attributs */
|
||||||
missing = 0;
|
missing = 0;
|
||||||
@ -8516,7 +8548,9 @@ int i, j, n, missing, first, index, n_mail, suppress, message_id, resubmit_or
|
|||||||
|
|
||||||
/* check for mail submissions */
|
/* check for mail submissions */
|
||||||
mail_param[0] = 0;
|
mail_param[0] = 0;
|
||||||
n_mail = 0;
|
mail_to = malloc(256);
|
||||||
|
mail_to[0] = 0;
|
||||||
|
mail_to_size = 256;
|
||||||
|
|
||||||
if (suppress)
|
if (suppress)
|
||||||
{
|
{
|
||||||
@ -8554,8 +8588,15 @@ int i, j, n, missing, first, index, n_mail, suppress, message_id, resubmit_or
|
|||||||
printf("\n%s to %s\n\n", str, list);
|
printf("\n%s to %s\n\n", str, list);
|
||||||
|
|
||||||
for (i=0 ; i<n ; i++)
|
for (i=0 ; i<n ; i++)
|
||||||
if (!compose_mail(lbs, mail_list[i], message_id, attrib, mail_param, &n_mail, *getparam("edit")))
|
{
|
||||||
return;
|
if ((int)strlen(mail_to) + (int)strlen(mail_list[i]) >= mail_to_size)
|
||||||
|
{
|
||||||
|
mail_to_size += 256;
|
||||||
|
mail_to = realloc(mail_to, mail_to_size);
|
||||||
|
}
|
||||||
|
strcat(mail_to, mail_list[i]);
|
||||||
|
strcat(mail_to, ",");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8568,12 +8609,27 @@ int i, j, n, missing, first, index, n_mail, suppress, message_id, resubmit_or
|
|||||||
get_user_line(lbs->name, user, NULL, NULL, user_email, email_notify);
|
get_user_line(lbs->name, user, NULL, NULL, user_email, email_notify);
|
||||||
|
|
||||||
if (email_notify[0])
|
if (email_notify[0])
|
||||||
if (!compose_mail(lbs, user_email, message_id, attrib, mail_param, &n_mail, *getparam("edit")))
|
{
|
||||||
return;
|
if ((int)strlen(mail_to) + (int)strlen(user_email) >= mail_to_size)
|
||||||
|
{
|
||||||
|
mail_to_size += 256;
|
||||||
|
mail_to = realloc(mail_to, mail_to_size);
|
||||||
|
}
|
||||||
|
strcat(mail_to, user_email);
|
||||||
|
strcat(mail_to, ",");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strlen(mail_to) > 0)
|
||||||
|
{
|
||||||
|
mail_to[strlen(mail_to)-1] = 0; /* strip last ',' */
|
||||||
|
compose_mail(lbs, mail_to, message_id, attrib, mail_param, *getparam("edit"));
|
||||||
|
}
|
||||||
|
|
||||||
|
free(mail_to);
|
||||||
|
|
||||||
for (i=0 ; i<MAX_ATTACHMENTS ; i++)
|
for (i=0 ; i<MAX_ATTACHMENTS ; i++)
|
||||||
if (buffer[i])
|
if (buffer[i])
|
||||||
free(buffer[i]);
|
free(buffer[i]);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Dutch messages by djek@xs4all.nl
|
# Dutch messages by djek@xs4all.nl
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# 29-9-2002
|
# 12-12-2002
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -201,3 +201,10 @@ Automatic email notifications=Automatisch e-mail aankondiging
|
|||||||
|
|
||||||
# New strings for V2.2.2
|
# New strings for V2.2.2
|
||||||
A old entry has been updated on %s = Een ouder bericht is op %s gewijzigd
|
A old entry has been updated on %s = Een ouder bericht is op %s gewijzigd
|
||||||
|
|
||||||
|
# New strings for V2.2.4
|
||||||
|
Collapse = Samenvatten
|
||||||
|
Expand = Uitbreiden
|
||||||
|
Full = Volledig
|
||||||
|
Summary = Samenvatting
|
||||||
|
Threaded = Berichtdraad
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user