laravel发邮件多账号轮流切换发邮件

为了解决laravel项目因每日邮件发送上限(通常为1000封)而可能遇到的问题,本文介绍了如何设置多邮箱账号轮流发送邮件。当主邮箱达到发送限制后,系统将自动切换到备用邮箱继续发送。主要步骤包括更新.env文件配置备用邮箱,创建backupMail.php配置文件,建立EmailServices.php服务类,以及在队列中处理邮件发送的OrderShipped.php和SendMailJob.php文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于本人项目发邮件次数比较多,而每个邮箱地址最大上限每日1000封受限。

为了避免第一个邮箱账号达到每日上限(邮件异常会返回错误码554,提示:Expected response code 354 but got code "554", with message "554 5.5.3 RP:TRC),项目还继续发送邮件,则启动备用邮箱号发送。

第一步:首先先配置.env配置备用邮件账号数据

#备用邮箱号
BACKUP_MAIL_DRIVER=smtp
BACKUP_MAIL_HOST=smtp.qiye.163.com
BACKUP_MAIL_PORT=465
BACKUP_MAIL_USERNAME=XXXXX@kingyee.com.cn
BACKUP_MAIL_PASSWORD=XXXXXXXXXXX
BACKUP_MAIL_FROM_ADDRESS=XXXXX@kingyee.com.cn
BACKUP_MAIL_FROM_NAME=XXXXX系统(备用)
BACKUP_MAIL_ENCRYPTION=ssl

第二步:在config目录新建文件名为backupMail.php

<?php
/**
 * 备用邮箱号 邮件配置
 */
return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
    |            "sparkpost", "log", "array"
    |
    */

    'driver' => env('BACKUP_MAIL_DRIVER', 'smtp'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('BACKUP_MAIL_HOST', 'smtp.mailgun.org'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => env('BACKUP_MAIL_PORT', 587),

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('BACKUP_MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('BACKUP_MAIL_FROM_NAME', 'Example'),
    ],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible def
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值