File: o2uk.cc

package info (click to toggle)
sms-pl 2.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 376 kB
  • ctags: 355
  • sloc: cpp: 2,618; perl: 109; makefile: 103; sh: 26
file content (29 lines) | stat: -rw-r--r-- 677 bytes parent folder | download
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 "o2uk.h"

using namespace std;

O2ukSMS::O2ukSMS(Config &config) : GenericSMS(config)
{
	sendmail_path = config["sendmail_path"];
	email = config["mailaddr"];
}

bool O2ukSMS::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 + "@o2.co.uk\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;
}