File: plusmail.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 (30 lines) | stat: -rw-r--r-- 704 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
30
#include <stdio.h>
#include "plusmail.h"

using namespace std;

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

bool PlusmailSMS::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 + "@text.plusgsm.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;
}