我在Linux系統上Linux:對於Sendmail的錯誤代碼未找到
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", "[email protected]");
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 to mailx");
nRc = -1;
}
return nRc;
}
此代碼工作正常展開下面的C++代碼。我必須確保在System上找到sendmail。因爲我有一個問題。 PATH變量設置不正確。因此在System上找不到sendmail。沒有錯誤消息,我收到。電子郵件似乎發出。但事實並非如此。如何在代碼(返回或錯誤代碼)中實現,如果Sendmail進程無法找到,我收到錯誤消息? thanx提前
thanx。它似乎工作 – beterman
偉大的。很高興聽到。你能接受答案嗎? – shayst