瀏覽代碼

增加自定义邮箱配置

luolongfei 4 年之前
父節點
當前提交
8360a3f7db
共有 7 個文件被更改,包括 40 次插入15 次删除
  1. 15 0
      .env.example
  2. 1 1
      README.md
  3. 1 1
      README_EN.md
  4. 2 2
      app/Console/FreeNom.php
  5. 10 6
      config.php
  6. 9 3
      libs/Mail.php
  7. 2 2
      libs/TelegramBot.php

+ 15 - 0
.env.example

@@ -34,6 +34,21 @@ TO=''
 
 # 是否启用邮件推送功能 true:启用 false:不启用 Whether to enable email push features true: enabled false: not enabled
 MAIL_ENABLE=true
+
+# 自定义邮箱配置 Custom email config
+# 如果你想使用除“QQ邮箱、163邮箱、Gmail、Outlook邮箱”外的第三方邮箱或者自建邮箱服务作为机器人邮箱,可以自定义邮箱配置,否则请不要配置这些项
+
+# SMTP 服务器 SMTP server
+MAIL_HOST=''
+
+# SMTP 端口号 SMTP port
+MAIL_PORT=''
+
+# 邮件加密方式 Email encryption method
+MAIL_ENCRYPTION=''
+
+# end 自定义邮箱配置 Custom email config
+
 ######################  end 通知邮件配置  #########################
 
 ######################  Telegram bot  #########################

+ 1 - 1
README.md

@@ -142,7 +142,7 @@ Documentation: [English version](https://github.com/luolongfei/freenom/blob/main
 
 上面介绍了三种邮箱的设置方法,如果你不想使用邮件推送,也可以使用 Telegram bot,灵活配置。在`.env`文件中,
 将`TELEGRAM_BOT_ENABLE`的值改为`true`,即可启用 Telegram bot,同样的,将`MAIL_ENABLE`的值改为`false`即可关闭邮件推送方式。
-Telegram bot 有两个配置项,一个是`chatID`(对应`.env`文件中的`TELEGRAM_CHAT_ID`),
+Telegram bot 有两个配置项,一个是`chat_id`(对应`.env`文件中的`TELEGRAM_CHAT_ID`),
 通过使用你的 Telegram 账户发送`/start`给`@userinfobot`即可以获取自己的id,
 另一个是`token`(对应`.env`文件中的`TELEGRAM_BOT_TOKEN`),你的 Telegram bot 令牌,你会创建 Telegram bot 就知道怎么获取,
 不多赘述。如何创建一个 Telegram bot 请参考:[官方文档](https://core.telegram.org/bots#6-botfather)

+ 1 - 1
README_EN.md

@@ -73,7 +73,7 @@ After logging in to Google Mail, go to [this page](https://accounts.google.com/b
 If you don't want to use email push, you can also use Telegram bot. In the `.env` file,
 Change the value of `TELEGRAM_BOT_ENABLE` to `true` to enable the Telegram bot.
 Similarly, change the value of `MAIL_ENABLE` to `false` to disable the mail push method.
-Telegram bot has two configuration items, one is `chatID` (corresponding to `TELEGRAM_CHAT_ID` in `.env` file),
+Telegram bot has two configuration items, one is `chat_id` (corresponding to `TELEGRAM_CHAT_ID` in `.env` file),
 You can get your own id by sending `/start` to `@userinfobot` using your Telegram account,
 The other is `token` (corresponding to `TELEGRAM_BOT_TOKEN` in the `.env` file), 
 your Telegram bot token, how to create a Telegram bot and how to get the token please refer to: 

+ 2 - 2
app/Console/FreeNom.php

@@ -77,7 +77,7 @@ class FreeNom
             'timeout' => self::TIMEOUT,
             CURLOPT_FOLLOWLOCATION => true,
             CURLOPT_AUTOREFERER => true,
-            'verify' => config('verifySSL'),
+            'verify' => config('verify_ssl'),
             'debug' => config('debug')
         ]);
 
@@ -224,7 +224,7 @@ class FreeNom
             ));
             system_log(sprintf("%s:续期结果如下:\n%s", $this->username, $result));
         } else {
-            if (config('noticeFreq') == 1) {
+            if (config('notice_freq') == 1) {
                 Mail::send(
                     '报告,今天没有域名需要续期',
                     [

+ 10 - 6
config.php

@@ -17,26 +17,30 @@ return [
          * 账户加授权码的方式登录,谷歌邮箱使用账户加密码的方式登录,请知悉。
          */
         'to' => env('TO'), // 用于接收通知的邮箱
-        'toName' => '主人', // 收件人名字
+        'recipient_name' => '主人', // 收件人名字
         'username' => env('MAIL_USERNAME'), // 机器人邮箱账户
         'password' => env('MAIL_PASSWORD'), // 机器人邮箱密码或授权码
         'enable' => env('MAIL_ENABLE'), // 是否启用,默认启用
 
-        // 'replyTo' => '[email protected]', // 接收回复的邮箱
-        // 'replyToName' => '作者', // 接收回复的人名
+        // 'reply_to' => '[email protected]', // 接收回复的邮箱
+        // 'reply_to_name' => '作者', // 接收回复的人名
+
+        'host' => env('MAIL_HOST'), // 邮件 SMTP 服务器
+        'port' => env('MAIL_PORT'), // 邮件 SMTP 端口
+        'encryption' => env('MAIL_ENCRYPTION'), // 邮件加密方式
     ],
 
     /**
      * Telegram Bot
      */
     'telegram' => [
-        'chatID' => env('TELEGRAM_CHAT_ID'), // 你的chat_id,通过发送“/start”给@userinfobot可以获取自己的id
+        'chat_id' => env('TELEGRAM_CHAT_ID'), // 你的chat_id,通过发送“/start”给@userinfobot可以获取自己的id
         'token' => env('TELEGRAM_BOT_TOKEN'), // Telegram Bot 的 token
         'enable' => env('TELEGRAM_BOT_ENABLE') // 是否启用,默认不启用
     ],
 
     'locale' => 'zh', // 指定语言包,位于resources/lang/目录下
-    'noticeFreq' => env('NOTICE_FREQ'), // 通知频率 0:仅当有续期操作的时候 1:每次执行
-    'verifySSL' => env('VERIFY_SSL'), // 请求时验证 SSL 证书行为,默认不验证,防止服务器证书过期或证书颁布者信息不全导致无法发出请求
+    'notice_freq' => env('NOTICE_FREQ'), // 通知频率 0:仅当有续期操作的时候 1:每次执行
+    'verify_ssl' => env('VERIFY_SSL'), // 请求时验证 SSL 证书行为,默认不验证,防止服务器证书过期或证书颁布者信息不全导致无法发出请求
     'debug' => env('DEBUG'),
 ];

+ 9 - 3
libs/Mail.php

@@ -54,7 +54,13 @@ class Mail
                 $secure = 'starttls';
                 $port = 587;
             } else {
-                throw new \Exception('不受支持的邮箱。目前仅支持谷歌邮箱、QQ邮箱以及163邮箱,推荐使用谷歌邮箱。');
+                $host = config('mail.host');
+                $secure = config('mail.encryption');
+                $port = (int)config('mail.port');
+                if (!($host && $secure && $port)) {
+                    throw new MailException('目前支持Gmail、QQ邮箱、163邮箱以及Outlook邮箱自动识别配置,其它类型的邮箱或者自建邮箱,'
+                        . '请追加配置 .env 文件中“自定义邮箱配置”的所有相关项,否则无法使用邮件服务。');
+                }
             }
 
             self::$mail->SMTPDebug = config('debug') ? 2 : 0; // Debug 0:关闭 1:客户端信息 2:客户端和服务端信息
@@ -97,8 +103,8 @@ class Mail
             throw new LlfException(env('ON_GITHUB_ACTIONS') ? 34520011 : 34520012);
         }
 
-        self::mail()->addAddress($to, config('mail.toName', '主人')); // 添加收件人,参数2选填
-        self::mail()->addReplyTo(config('mail.replyTo', '[email protected]'), config('mail.replyToName', '作者')); // 备用回复地址,收到的回复的邮件将被发到此地址
+        self::mail()->addAddress($to, config('mail.recipient_name', '主人')); // 添加收件人,参数2选填
+        self::mail()->addReplyTo(config('mail.reply_to', '[email protected]'), config('mail.reply_to_name', '作者')); // 备用回复地址,收到的回复的邮件将被发到此地址
 
         /**
          * 抄送和密送都是添加收件人,抄送方式下,被抄送者知道除被密送者外的所有的收件人,密送方式下,

+ 2 - 2
libs/TelegramBot.php

@@ -37,7 +37,7 @@ class TelegramBot
 
     public function __construct()
     {
-        $this->chatID = config('telegram.chatID');
+        $this->chatID = config('telegram.chat_id');
         $this->token = config('telegram.token');
 
         $this->client = new Client([
@@ -46,7 +46,7 @@ class TelegramBot
             ],
             'cookies' => false,
             'timeout' => self::TIMEOUT,
-            'verify' => config('verifySSL'),
+            'verify' => config('verify_ssl'),
 //            'http_errors' => false,
             'debug' => config('debug')
         ]);