c++ - Linux: Error Code for Sendmail not Found -
i deployed following c++ code on linux system
int sendemail ( string semailaddress, string semailsubject , string semailtext ) { int nrc = nok; // send email here const int nbuffersize = 55000; static char szcommand [ nbuffersize ] = { 0 }; const char * szemailtext = null; file *fpipe = popen("sendmail -t", "w"); szemailtext=semailtext.c_str(); if ( fpipe != null ) { fprintf(fpipe, "to: %s\n", semailaddress.c_str()); fprintf(fpipe, "from: %s\n", "test@mail.de"); fprintf(fpipe, "subject: %s\n\n", semailsubject.c_str()); fwrite(semailtext.c_str(), 1, strlen(semailtext.c_str()), fpipe); pclose(fpipe); } else { logger_log ( 1 , "error: cannot create pipe mailx" ); nrc = -1; } return nrc; }
this code works fine. have ensure sendmail should found on system. because got problem. path variable not set correct. therefore sendmail not found on system. there no error message, received. email seems send out. not. how can realize within code (return or error code), receive error message, if sendmail process not found? thanx in advance
i'm not sure, think manual there answers:
1. popen calls /bin/sh -c <your command> guess popen succeed unless /bin/sh not found
2. should check return code:
int ret_code=pclose(fpipe); if (ret_code != 0) { // error handling comes here }
from manual page (man popen)
the pclose() function waits associated process terminate , returns exit status of command returned wait4(2).
...
the pclose() function returns -1 if wait4(2) returns error, or other error detected.
Comments
Post a Comment