forked from verdnatura/hedera-web
Notify errors to replyTo for automated emails
This commit is contained in:
parent
3f0b762650
commit
230eae9eda
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.406.43) stable; urgency=low
|
hedera-web (1.406.44) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hedera-web",
|
"name": "hedera-web",
|
||||||
"version": "1.406.43",
|
"version": "1.406.44",
|
||||||
"description": "Verdnatura web page",
|
"description": "Verdnatura web page",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"<p>The response from the remote server was:</p>": "<p>La respuesta del servidor remoto ha sido:</p>"
|
||||||
|
,"An automated message could not be delivered": "Un mensaje automatizado no se ha podido entregar"
|
||||||
|
}
|
|
@ -4,13 +4,15 @@ require_once('libphp-phpmailer/PHPMailerAutoload.php');
|
||||||
|
|
||||||
class Mail extends Vn\Lib\Method {
|
class Mail extends Vn\Lib\Method {
|
||||||
function run($db) {
|
function run($db) {
|
||||||
$db->selectDb('vn2008');
|
|
||||||
$db->query('START TRANSACTION');
|
$db->query('START TRANSACTION');
|
||||||
|
|
||||||
$mailer = new Vn\Web\Mailer($db);
|
$mailer = new Vn\Web\Mailer($db);
|
||||||
$res = $db->query(
|
$res = $db->query(
|
||||||
'SELECT * FROM mail WHERE sent = 0 ORDER BY DATE_ODBC DESC
|
'SELECT * FROM vn.mail WHERE sent = 0
|
||||||
LIMIT 20 FOR UPDATE');
|
ORDER BY creationDate
|
||||||
|
LIMIT 20
|
||||||
|
FOR UPDATE'
|
||||||
|
);
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
|
@ -19,11 +21,11 @@ class Mail extends Vn\Lib\Method {
|
||||||
$status = 'OK';
|
$status = 'OK';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$mail = $mailer->createObject($row->to, $row->text, $row->subject);
|
$mail = $mailer->createObject($row->sender, $row->body, $row->subject);
|
||||||
$mail->AddReplyTo($row->reply_to, $row->reply_to);
|
$mail->AddReplyTo($row->replyTo, $row->replyTo);
|
||||||
|
|
||||||
if (!empty($row->path)) {
|
if (!empty($row->attachment)) {
|
||||||
$attachment = '/mnt/cluster/pdfs/'. $row->path;
|
$attachment = '/mnt/cluster/pdfs/'. $row->attachment;
|
||||||
|
|
||||||
if (file_exists($attachment))
|
if (file_exists($attachment))
|
||||||
$mail->AddAttachment($attachment, '');
|
$mail->AddAttachment($attachment, '');
|
||||||
|
@ -32,15 +34,30 @@ class Mail extends Vn\Lib\Method {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$mail->Send())
|
if (!$mail->Send())
|
||||||
throw new Exception('Send error: '.$mail->ErrorInfo);
|
throw new Exception($mail->ErrorInfo);
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$sent = 2;
|
$sent = 2;
|
||||||
$status = $e->getMessage();
|
$status = $e->getMessage();
|
||||||
|
|
||||||
|
if ($row->replyTo) {
|
||||||
|
$errorMail = $mailer->createObject($row->replyTo,
|
||||||
|
s('<p>The response from the remote server was:</p>')
|
||||||
|
."<p>$status</p>",
|
||||||
|
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]);
|
[$sent, $status, $row->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue