I have attempted to alter the code using a "cat'ed" file rather than an echoed variable.
The behavior is still the same.
QString sALERT
= "Your shoe is untied.";
QString sEMAIL
= "someone@some.dom";
sMsg = "An ALERT Message was received from the Client with IP address " + sIP + ".\n\n"
"Message: " + sALERT;
// Create file to write the message into.
QString sAlertFile
= sSMARTHOME
+ "/tmp/alert.txt";
FILE *fAlertFile;
// Open the alert file for write only.
if ((fAlertFile = fopen(sAlertFile.toAscii(), "w")) == NULL)
{
logger(".... Unable to alert file " + sAlertFile + " for email.");
}
else
{
// Write the message and close the file
fputs(sMsg.toAscii(), fAlertFile);
fclose(fAlertFile);
QStringLilst slCvtArgs;
slCvtArgs.clear();
slCvtArgs << "-c" << "\"/bin/cat" << "\'" + sAlertFile + "\'" << "|" << "/bin/mail" << "-s" << "\'SMART ALERT\'" << sEMAIL << "\"";
// Build a message to write to the log file.
sMsg = sCMD;
for (int iString = 0; iString < slCvtArgs.size(); iString++)
sMsg = sMsg + " " + slCvtArgs.at(iString);
// Write message to the log file.
logger("... Sending email using the following command:");
logger("...... " + sMsg);
// Now execute the mail commmand.
pCVT.execute(sCMD, slCvtArgs);
if (pCVT.exitCode())
{
sMsg.setNum(pCVT.exitCode());
logger("... EMAIL exit code: " + sMsg);
}
}
QString sCMD = "/bin/sh";
QString sALERT = "Your shoe is untied.";
QString sEMAIL = "someone@some.dom";
QString sIP = "some.IP.address";
sMsg = "An ALERT Message was received from the Client with IP address " + sIP + ".\n\n"
"Message: " + sALERT;
// Create file to write the message into.
QString sAlertFile = sSMARTHOME + "/tmp/alert.txt";
FILE *fAlertFile;
// Open the alert file for write only.
if ((fAlertFile = fopen(sAlertFile.toAscii(), "w")) == NULL)
{
logger(".... Unable to alert file " + sAlertFile + " for email.");
}
else
{
// Write the message and close the file
fputs(sMsg.toAscii(), fAlertFile);
fclose(fAlertFile);
QStringLilst slCvtArgs;
slCvtArgs.clear();
slCvtArgs << "-c" << "\"/bin/cat" << "\'" + sAlertFile + "\'" << "|" << "/bin/mail" << "-s" << "\'SMART ALERT\'" << sEMAIL << "\"";
// Build a message to write to the log file.
sMsg = sCMD;
for (int iString = 0; iString < slCvtArgs.size(); iString++)
sMsg = sMsg + " " + slCvtArgs.at(iString);
// Write message to the log file.
logger("... Sending email using the following command:");
logger("...... " + sMsg);
// Now execute the mail commmand.
QProcess pCVT;
pCVT.execute(sCMD, slCvtArgs);
if (pCVT.exitCode())
{
sMsg.setNum(pCVT.exitCode());
logger("... EMAIL exit code: " + sMsg);
}
}
To copy to clipboard, switch view to plain text mode
Karl
Bookmarks