From 230eae9eda1897cc8003d600a7e49d50524a7c30 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 7 May 2019 17:06:40 +0200 Subject: [PATCH] Notify errors to replyTo for automated emails --- debian/changelog | 2 +- package.json | 2 +- rest/misc/locale/es.json | 4 ++++ rest/misc/mail.php | 35 ++++++++++++++++++++++++++--------- 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 rest/misc/locale/es.json diff --git a/debian/changelog b/debian/changelog index 5fcd7fbd..9a31018f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.406.43) stable; urgency=low +hedera-web (1.406.44) stable; urgency=low * Initial Release. diff --git a/package.json b/package.json index 2a2c7cda..8ec674bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "1.406.43", + "version": "1.406.44", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": { diff --git a/rest/misc/locale/es.json b/rest/misc/locale/es.json new file mode 100644 index 00000000..ad1f0198 --- /dev/null +++ b/rest/misc/locale/es.json @@ -0,0 +1,4 @@ +{ + "

The response from the remote server was:

": "

La respuesta del servidor remoto ha sido:

" + ,"An automated message could not be delivered": "Un mensaje automatizado no se ha podido entregar" +} \ No newline at end of file diff --git a/rest/misc/mail.php b/rest/misc/mail.php index c9245aac..f723c1c5 100644 --- a/rest/misc/mail.php +++ b/rest/misc/mail.php @@ -4,13 +4,15 @@ require_once('libphp-phpmailer/PHPMailerAutoload.php'); class Mail extends Vn\Lib\Method { function run($db) { - $db->selectDb('vn2008'); $db->query('START TRANSACTION'); $mailer = new Vn\Web\Mailer($db); $res = $db->query( - 'SELECT * FROM mail WHERE sent = 0 ORDER BY DATE_ODBC DESC - LIMIT 20 FOR UPDATE'); + 'SELECT * FROM vn.mail WHERE sent = 0 + ORDER BY creationDate + LIMIT 20 + FOR UPDATE' + ); $count = 0; @@ -19,11 +21,11 @@ class Mail extends Vn\Lib\Method { $status = 'OK'; try { - $mail = $mailer->createObject($row->to, $row->text, $row->subject); - $mail->AddReplyTo($row->reply_to, $row->reply_to); + $mail = $mailer->createObject($row->sender, $row->body, $row->subject); + $mail->AddReplyTo($row->replyTo, $row->replyTo); - if (!empty($row->path)) { - $attachment = '/mnt/cluster/pdfs/'. $row->path; + if (!empty($row->attachment)) { + $attachment = '/mnt/cluster/pdfs/'. $row->attachment; if (file_exists($attachment)) $mail->AddAttachment($attachment, ''); @@ -32,15 +34,30 @@ class Mail extends Vn\Lib\Method { } if (!$mail->Send()) - throw new Exception('Send error: '.$mail->ErrorInfo); + throw new Exception($mail->ErrorInfo); $count++; } catch (Exception $e) { $sent = 2; $status = $e->getMessage(); + + if ($row->replyTo) { + $errorMail = $mailer->createObject($row->replyTo, + s('

The response from the remote server was:

') + ."

$status

", + s('An automated message could not be delivered') + ); + $errorMail->AddStringAttachment( + $mail->getSentMIMEMessage(), + 'Undelivered Message', + '8bit', + 'message/rfc822' + ); + $errorMail->Send(); + } } - $db->query('UPDATE mail SET sent = #, error = # WHERE id = #', + $db->query('UPDATE vn.mail SET sent = #, status = # WHERE id = #', [$sent, $status, $row->id]); }