我在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