1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <stdio.h>
#include "eranet.h"
using namespace std;
EranetSMS::EranetSMS(Config &config) : GenericSMS(config)
{
sendmail_path = config["sendmail_path"];
email = config["mailaddr"];
}
bool EranetSMS::Send(const std::string &phone_no, const std::string &message)
{
bool ok = false;
string cmd, buffer;
FILE *pf;
cmd = sendmail_path + " -f \"" + email + "\" -t";
if ((pf = popen(cmd.c_str(), "w"))) {
buffer = "From: " + email + "\nTo: " + phone_no.substr(3) + "@eranet.pl\n" +
"Subject: " + message + "\n\n" + message + "\n.\n";
ok = fprintf(pf, "%s", buffer.c_str()) == (int)buffer.length();
pclose(pf);
if (!ok) throw Exception("[1] - popen()");
}
return ok;
}
|