Changeset 2168


Ignore:
Timestamp:
05/19/06 16:47:51 (14 years ago)
Author:
dietz
Message:

Added argument to SendMail?() so user can specify the "From" field of
outgoing email. Defaults to %USERNAME%@%COMPUTERNAME% if a null pointer
or empty string is passed in the argument. Previously defaulted to
"root@mailserver".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libsrc/winnt/sendmail.c

    r1244 r2168  
    88 *    Revision history: 
    99 *     $Log$ 
     10 *     Revision 1.6  2006/05/19 23:47:51  dietz 
     11 *     Added argument to SendMail() so user can specify the "From" field of 
     12 *     outgoing email. Defaults to %USERNAME%@%COMPUTERNAME% if a null pointer 
     13 *     or empty string is passed in the argument. Previously defaulted to 
     14 *     "root@mailserver". 
     15 * 
    1016 *     Revision 1.5  2003/06/11 19:13:14  kohler 
    1117 *     Increased BUFFSIZE from 200 to 250 in define statment. 
     
    6066#define BUFFSIZE 250 
    6167 
    62 static char *Sender = NULL; 
     68static char Sender[BUFFSIZE]; 
     69static int  SenderInit = 0; 
    6370 
    6471int SendMail( char person[][60], int nmail, char *mailProg, char *subject,  
    65               char *msg, char *msgPrefix, char *msgSuffix, char *mailServer ) 
     72              char *msg, char *msgPrefix, char *msgSuffix, char *mailServer, 
     73              char *from ) 
    6674{ 
    6775   FILE                *fp; 
     
    7078   char                pathBuffer[BUFFSIZE]; 
    7179   char                tempFilename[MAX_PATH]; 
    72    char                commandLine[BUFFSIZE]; 
     80   char                commandLine[BUFFSIZE*4]; 
    7381   STARTUPINFO         startUpInfo; 
    7482   BOOL                success; 
     
    8189/* Check arguments 
    8290   ***************/ 
    83    if ( nmail < 1 ) 
    84       return -1; 
    85  
    86 /* Have Sender point to this computer's name 
    87    *****************************************/ 
    88    if ( Sender == NULL )  Sender = getenv( "COMPUTERNAME" ); 
     91   if ( nmail < 1 )  return -1; 
     92 
     93/* Do once: load Sender with thisuser@thiscomputer 
     94   ***********************************************/ 
     95   if ( !SenderInit )  
     96   {  
     97      char *user     = getenv( "USERNAME" ); 
     98      char *computer = getenv( "COMPUTERNAME" ); 
     99      int   len = strlen(user)+strlen(computer)+1; 
     100      if( len < BUFFSIZE )   sprintf( Sender, "%s@%s", user, computer ); 
     101      else if( strlen(computer) < BUFFSIZE ) strcpy( Sender, computer ); 
     102      else                                   strcpy( Sender, "nobody" ); 
     103      SenderInit = 1; 
     104   } 
    89105 
    90106/* Get the path of the temporary file directory 
     
    132148   strcat( commandLine, tempFilename ); 
    133149 
    134    if (subject != NULL) 
    135    { 
    136        sprintf ( tmp, " -s \"%s\"", subject ); 
     150   if( subject != NULL ) 
     151   { 
     152       sprintf( tmp, " -s \"%s\"", subject ); 
    137153       strcat( commandLine, tmp ); 
    138154   } 
    139155 
    140    strcat( commandLine, " -f root@" ); 
    141    strcat( commandLine, mailServer ); 
    142    strcat( commandLine, " -i " ); 
    143    strcat( commandLine, Sender ); 
     156   strcat( commandLine, " -f " ); 
     157   if( from && strlen(from)!=0 ) strcat( commandLine, from ); 
     158   else                          strcat( commandLine, Sender ); 
     159 
    144160   strcat( commandLine, " -server " ); 
    145161   strcat( commandLine, mailServer ); 
     162 
    146163   strcat( commandLine, " -t " ); 
    147164   strcat( commandLine, &person[0][0] ); 
    148  
    149165   for ( i = 1; i < nmail; i++ ) 
    150166   { 
Note: See TracChangeset for help on using the changeset viewer.