Merge changes submitted by Matt Gagne <matt.gagne@state.vt.us>
[inoclam.git] / smtp.cxx
blob145e7fbfc229fa279b5ef7e03dfbad9f6a6baf1b
1 /*
2 * inoclam - Inotify+ClamAV virus scanner
3 * Copyright (C) 2007 Vermont Department of Taxes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Contributor(s):
20 * Tom Cort <tom.cort@state.vt.us>
21 * Matt Gagne <matt.gagne@state.vt.us>
24 #include <exception>
25 #include <jwsmtp/jwsmtp.h>
26 #include <libdaemon/dlog.h>
27 #include <stdlib.h>
28 #include <string>
30 #include "smtp.hxx"
32 /**
33 * Sends an E-Mail.
35 void smtp_send(char *subject, std::string * body, config * conf)
38 cfg_bool_t smtp_enabled = conf->getSMTPEnabled();
39 char *smtp_host = conf->getHost();
40 int smtp_port = conf->getPort();
41 char *smtp_to = conf->getTo();
42 char *smtp_from = conf->getFrom();
43 const char *smtp_body = body->c_str();
45 if (smtp_enabled == cfg_false) {
46 return;
49 if (smtp_host == NULL || smtp_to == NULL || smtp_from == NULL || smtp_port < 1 || smtp_port > 65535 || subject == NULL || smtp_body == NULL) {
50 daemon_log(LOG_INFO, "Incomplete Configuration or Message -- Not Sending E-Mail");
51 return;
54 /* Why are there no C libraries for sending mail that are this simple? */
55 jwsmtp::mailer * mail;
56 mail = new jwsmtp::mailer(smtp_to, smtp_from, subject, smtp_body, smtp_host, smtp_port, false);
57 mail->send();
58 delete mail;