{"record":{"id":"157ca685248d91ba","repo":"yikart/AiToEarn","slug":"errhttpback-err-mail-send-fail","errorCode":"ErrHttpBack.err_mail_send_fail","errorMessage":"err_mail_send_fail","messagePattern":"err_mail_send_fail","errorType":"error_code","errorClass":"AppHttpException","httpStatus":400,"severity":"error","filePath":"project/aitoearn-electron/server/src/user/userLogin.controller.ts","lineNumber":440,"sourceCode":"    }\n\n    // 没有进行创建逻辑\n    const code = getRandomString(6, true);\n\n    this.redisService.setKey(\n      `userMailLogin:${code}`,\n      { mail: mail, status: 0 },\n      60 * 5,\n    );\n\n    // 发验证码邮件,邮箱号和code\n    const mailRes = await this.mailService.sendEmail({\n      to: mail,\n      subject: 'aitoearn regist',\n      html: `<a href=\"https://api.aitoearn.cn/api/user/login/mail/regist/url?mail=${mail}&code=${code}\">点击此处进行注册</a>`,\n    });\n\n    if (!mailRes) throw new AppHttpException(ErrHttpBack.err_mail_send_fail);\n\n    return {\n      type: 'regist',\n      code: code,\n    };\n  }\n\n  // TODO: 后期改成返回页面\n  @ApiOperation({\n    summary: '邮箱注册',\n    description: '用户点击链接后,进行注册',\n  })\n  @Public()\n  @Get('mail/regist/url')\n  async registByMail(\n    @Query(new ParamsValidationPipe()) query: MailRegistUrlDto,\n  ) {\n    const { mail, code } = query;","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/user/userLogin.controller.ts#L422-L458","documentation":"err_mail_send_fail is thrown during email-registration (loginByMail regist flow) when mailService.sendEmail returns falsy, meaning the registration email with the confirmation link could not be sent. The registration attempt is aborted and the client is told mail delivery failed.","triggerScenarios":"POST initiating mail registration where the underlying mail delivery call fails or reports failure: SMTP misconfiguration, invalid/expired mail provider credentials, unreachable SMTP host, rejected recipient address, or mailService returning false on error instead of throwing.","commonSituations":"Missing or wrong SMTP env vars (host/port/user/pass) in a deployment; mail provider credentials rotated or quota exhausted; recipient domain hard-bouncing; firewall blocking outbound SMTP ports (25/465/587).","solutions":["Check the mailService/SMTP configuration env vars (host, port, auth) in the running environment","Send a test email through the same mailService to isolate the failure","Verify network egress allows SMTP to the mail provider, and check provider quota/bounce logs","If using a sandbox/dev environment, confirm the mail provider account is active and the recipient address is valid"],"exampleFix":"// before\n// .env: SMTP_HOST=, SMTP_USER= (empty)\n// after\n// .env: SMTP_HOST=smtp.example.com, SMTP_PORT=465, SMTP_USER=noreply@example.com, SMTP_PASS=***\n// then restart the server and retry registration","handlingStrategy":"fallback","validationCode":"if (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(mail)) {\n  showFormError('Invalid mail address');\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.startMailRegistration(mail);\n} catch (e) {\n  if (e.response?.data?.code === 'err_mail_send_fail') {\n    showRetryBanner('Registration email could not be sent. Check your address or retry later.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify SMTP env vars (host, port, credentials) on every deployment","Send a startup health-check email to catch mail misconfiguration early","Monitor mail provider bounce/quota dashboards","Validate recipient addresses client-side before triggering registration emails"],"tags":["email","smtp","registration","configuration"],"backgroundTag":"email-send-failed","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}