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.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "hedera-web",
|
||||
"version": "1.406.43",
|
||||
"version": "1.406.44",
|
||||
"description": "Verdnatura web page",
|
||||
"license": "GPL-3.0",
|
||||
"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 {
|
||||
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('<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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue