You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SendGrid闲置20-24小时后无法发送邮件问题求助

SendGrid闲置后停止发送邮件问题

问题描述

系统闲置20-24小时(上次发送邮件后无任何邮件发送操作)后,SendGrid会停止向所有收件人发送邮件。临时解决办法为本地启动服务器并通过Postman调用触发邮件的API,或是重启生产服务器。

预期行为

发送邮件时若出现错误,数据库中对应通知的状态应更新为fail,但实际状态仍停留在默认值sending。

实际行为

  • 当前通知状态未更新,始终处于sending状态
  • 后续所有邮件均无法发送
  • 已确认未达到SendGrid设置的每日100封邮件限制

发送邮件的服务器代码

export async function sendGridMails({
  to,
  metadata,
  notificationType,
  ...rest
}: {
  to: string;
  metadata: any;
  notificationType: any;
  _id: ObjectId;
}) {
  const {
    email: {
      subject
    },
  } = metadata;

  const html = templates[notificationType](metadata);

  const msg = {
    to,
    from: config.emailSettings.email, // Use the email address or domain you verified above
    subject,
    html,
  };

  try {
    console.log("sending sgmails to ", {
      to,
      subject
    });
    await sgMail.send(msg);
    console.log("Mail sent ", {
      to,
      subject
    })
    await DbServices.findOneAndUpdate({
      query: {
        _id: rest._id
      },
      model: MODEL_NAMES.NOTIFICATION_MODEL,
      updateParam: {
        status: 'sent'
      },
    });
  } catch (error: any) {
    logger.error(`Error occured while sending mail to ${to} about ${metadata.email.subject}`);
    await DbServices.findOneAndUpdate({
      query: {
        _id: rest._id
      },
      model: MODEL_NAMES.NOTIFICATION_MODEL,
      updateParam: {
        status: 'failed'
      },
    });
  }
}

相关验证信息

  • SendGrid后台显示未收到相关邮件请求:
    SendGrid未收到请求截图
  • 数据库中通知状态:
    数据库状态截图

内容的提问来源于stack exchange,提问作者Joy Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 21:58:22