Skip to content

Commit

Permalink
Merge branch 'release/4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 9, 2024
2 parents c502810 + 853abfb commit ef1bad8
Show file tree
Hide file tree
Showing 222 changed files with 2,285 additions and 6,164 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v4.1.0
## 04/09/2024

1. [](#improved)
* Update vendor libraries for Mailer to latest `5.4` versions
* When you send an email you can use `Email::getLastSendMessage()` and `Email::getLastSendDebug()` methods to get information about the email processing.

# v4.0.4
## 07/10/2023

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Email
slug: email
type: plugin
version: 4.0.4
version: 4.1.0
testing: false
description: Enables the emailing system for Grav
icon: envelope
Expand Down
47 changes: 32 additions & 15 deletions classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Email

protected $log;

protected $message;
protected $debug;

public function __construct()
{
$this->initMailer();
Expand Down Expand Up @@ -82,35 +85,31 @@ public function message(string $subject = null, string $body = null, string $con
/**
* Send email.
*
* @param Message $message
* @param Envelope|null $envelope
* @param Message $message
* @param Envelope|null $envelope
* @return int
*/
public function send(Message $message, Envelope $envelope = null): int
{
$status = '🛑 ';
$sent_msg = null;
$debug = null;

try {
$sent_msg = $this->transport->send($message->getEmail(), $envelope);
$return = 1;
$status = '';
$debug = $sent_msg->getDebug();
$status = 1;
$this->message = '';
$this->debug = $sent_msg->getDebug();
} catch (TransportExceptionInterface $e) {
$return = 0;
$status .= $e->getMessage();
$debug = $e->getDebug();
$status = 0;
$this->message = '🛑 ' . $e->getMessage();
$this->debug = $e->getDebug();
}

if ($this->debug()) {
$log_msg = "Email sent to %s at %s -> %s\n%s";
$to = $this->jsonifyRecipients($message->getEmail()->getTo());
$msg = sprintf($log_msg, $to, date('Y-m-d H:i:s'), $status, $debug);
$this->log->addInfo($msg);
$message = sprintf($log_msg, $to, date('Y-m-d H:i:s'), $this->message, $this->debug);
$this->log->addInfo($message);
}

return $return;
return $status;
}

/**
Expand Down Expand Up @@ -453,6 +452,24 @@ protected static function getTransport(): Transport\TransportInterface
return $transport;
}

/**
* Get any message from the last send attempt
* @return string|null
*/
public function getLastSendMessage(): ?string
{
return $this->message;
}

/**
* Get any debug information from the last send attempt
* @return string|null
*/
public function getLastSendDebug(): ?string
{
return $this->debug;
}

/**
* @param array $recipients
* @return string
Expand Down
Loading

0 comments on commit ef1bad8

Please sign in to comment.