- quickmail_set_body (mail, body.c_str());
- quickmail_add_attachment_file (mail, zip_file.string().c_str(), "application/zip");
-
- char const* error = quickmail_send (
- mail,
- Config::instance()->mail_server().c_str(),
- Config::instance()->mail_port(),
- Config::instance()->mail_user().c_str(),
- Config::instance()->mail_password().c_str()
- );
-
- if (error) {
- quickmail_destroy (mail);
- throw KDMError (
- String::compose (
- "Failed to send KDM email to %1 (%2)",
- Config::instance()->mail_server(),
- error
- )
- );
+ Emailer email (config->kdm_from(), i.cinema->emails, subject, body);
+
+ BOOST_FOREACH (string i, config->kdm_cc()) {
+ email.add_cc (i);
+ }
+ if (!config->kdm_bcc().empty ()) {
+ email.add_bcc (config->kdm_bcc ());
+ }
+
+ email.add_attachment (zip_file, name_format.get(name_values) + ".zip", "application/zip");
+
+ Config* c = Config::instance ();
+
+ try {
+ email.send (c->mail_server(), c->mail_port(), c->mail_user(), c->mail_password());
+ } catch (...) {
+ if (log) {
+ log->log ("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);
+ log->log (email.email(), LogEntry::TYPE_DEBUG_EMAIL);
+ log->log ("Email session follows", LogEntry::TYPE_DEBUG_EMAIL);
+ log->log (email.notes(), LogEntry::TYPE_DEBUG_EMAIL);
+ }
+ throw;
+ }
+
+ if (log) {
+ log->log ("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);
+ log->log (email.email(), LogEntry::TYPE_DEBUG_EMAIL);
+ log->log ("Email session follows", LogEntry::TYPE_DEBUG_EMAIL);
+ log->log (email.notes(), LogEntry::TYPE_DEBUG_EMAIL);