From 86ab628bcc98de8d39bf605e688ccbac9d8b3f87 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 21 Jul 2024 21:07:22 +0900 Subject: [PATCH] General adjustments to naver cloud mailer driver --- .../framework/drivers/mail/ncloud_mailer.php | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/common/framework/drivers/mail/ncloud_mailer.php b/common/framework/drivers/mail/ncloud_mailer.php index 025ed180e..951772d0e 100644 --- a/common/framework/drivers/mail/ncloud_mailer.php +++ b/common/framework/drivers/mail/ncloud_mailer.php @@ -3,16 +3,26 @@ namespace Rhymix\Framework\Drivers\Mail; /** - * The ncloud Outbound Mailer mail driver. + * The NAVER Cloud Outbound Mailer mail driver. */ class Ncloud_Mailer extends Base implements \Rhymix\Framework\Drivers\MailInterface { /** * The API URL. */ - protected static $_url = 'https://mail.apigw.ntruss.com/api/v1'; + protected static $_url = 'https://mail.apigw.ntruss.com/api/v1/mails'; protected static $_timeout = 10; + /** + * Get the human-readable name of this mail driver. + * + * @return string + */ + public static function getName() + { + return 'NAVER Cloud Outbound Mailer'; + } + /** * Get the list of configuration fields required by this mail driver. * @@ -137,31 +147,33 @@ class Ncloud_Mailer extends Base implements \Rhymix\Framework\Drivers\MailInterf } } + // Generate the NAVER cloud gateway signature. $timestamp = floor(microtime(true) * 1000); - - // Define connection options. + $signature = $this::_makeSignature($timestamp, $this->_config['api_key'], $this->_config['api_secret']); $headers = array( - 'Content-Type' => 'application/json', 'x-ncp-apigw-timestamp' => $timestamp, 'x-ncp-iam-access-key' => $this->_config['api_key'], - 'x-ncp-apigw-signature-v2' => $this::_makeSignature($timestamp, $this->_config['api_key'], $this->_config['api_secret']), + 'x-ncp-apigw-signature-v2' => $signature, ); // Send the API request. try { - $request = \Rhymix\Framework\HTTP::post(self::$_url . "/mails", $data, $headers, [], ['timeout' => self::$_timeout]); + $request = \Rhymix\Framework\HTTP::post(self::$_url, [], $headers, [], [ + 'timeout' => self::$_timeout, + 'json' => $data, + ]); $result = @json_decode($request->getBody()->getContents()); } catch (\Exception $e) { - $message->errors[] = 'Navercloudmail: Request error: ' . $e->getMessage(); + $message->errors[] = 'NAVER Cloud Outbound Mailer: ' . $e->getMessage(); return false; } if (isset($result->error)) { - $message->errors[] = 'Navercloudmail: ' . $result->error->message . PHP_EOL . $result->error->details; + $message->errors[] = 'NAVER Cloud Outbound Mailer: ' . $result->error->message . PHP_EOL . $result->error->details; return false; } else