NodeMailer node.js Send Error: %s' 'self signed certificate'

编程入门 行业动态 更新时间:2024-10-23 04:48:34

NodeMailer  node.<a href=https://www.elefans.com/category/jswz/34/1771451.html style=js Send Error: %s' 'self signed certificate'"/>

NodeMailer node.js Send Error: %s' 'self signed certificate'

(1/1) Swift_TransportException
Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients

 

邮件的发件人名称与邮件的from 邮箱地址对应
xiaojian => xiaojian@163

 

[2019-06-21T04:04:15.878] [DEBUG] default - { component: 'smtp-connection', sid: 'kzpfkQU1PEM', tnx: 'smtp' } 'Closing connection to the server using "%s"' 'end'
[2019-06-21T04:04:15.879] [ERROR] default - { component: 'mail',
  err: { Error: self signed certificate
    at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket._finishInit (_tls_wrap.js:639:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code: 'ESOCKET', command: 'CONN' },
  tnx: 'transport',
  action: 'send' } 'Send Error: %s' 'self signed certificate'

配置项中添加  "ignoreTLS": true, 即可

Mailer.prototype.createTransport = function() {this.transport = nodemailer.createTransport({"service": config.email.service,"auth": {"user": config.email.user,"pass": config.email.pass},"logger": logger,"host": config.email.host,"port": config.email.port,"secure": config.email.secure,"ignoreTLS": true,});logger.debug('SMTP configured');return this;
};

.php/how-do/bfIL/nodejs-nodemailer-nodemailer-depth-zero-self-signed-cert

 

service.json

{"1und1": {"host": "smtp.1und1.de","port": 465,"secure": true,"authMethod": "LOGIN"},"AOL": {"domains": ["aol"],"host": "smtp.aol","port": 587},"DebugMail": {"host": "debugmail.io","port": 25},"DynectEmail": {"aliases": ["Dynect"],"host": "smtp.dynect","port": 25},"FastMail": {"domains": ["fastmail.fm"],"host": "smtp.fastmail","port": 465,"secure": true},"GandiMail": {"aliases": ["Gandi", "Gandi Mail"],"host": "mail.gandi","port": 587},"Gmail": {"aliases": ["Google Mail"],"domains": ["gmail", "googlemail"],"host": "smtp.gmail","port": 465,"secure": true},"Godaddy": {"host": "smtpout.secureserver","port": 25},"GodaddyAsia": {"host": "smtp.asia.secureserver","port": 25},"GodaddyEurope": {"host": "smtp.europe.secureserver","port": 25},"hot.ee": {"host": "mail.hot.ee"},"Hotmail": {"aliases": ["Outlook", "Outlook", "Hotmail"],"domains": ["hotmail", "outlook"],"host": "smtp.live","port": 587},"iCloud": {"aliases": ["Me", "Mac"],"domains": ["me", "mac"],"host": "smtp.mail.me","port": 587},"mail.ee": {"host": "smtp.mail.ee"},"Mail.ru": {"host": "smtp.mail.ru","port": 465,"secure": true},"Maildev": {"port": 1025,"ignoreTLS": true},"Mailgun": {"host": "smtp.mailgun","port": 465,"secure": true},"Mailjet": {"host": "in.mailjet","port": 587},"Mailosaur": {"host": "mailosaur.io","port": 25},"Mailtrap": {"host": "smtp.mailtrap.io","port": 2525},"Mandrill": {"host": "smtp.mandrillapp","port": 587},"Naver": {"host": "smtp.naver","port": 587},"One": {"host": "send.one","port": 465,"secure": true},"OpenMailBox": {"aliases": ["OMB", "openmailbox"],"host": "smtp.openmailbox","port": 465,"secure": true},"Outlook365": {"host": "smtp.office365","port": 587,"secure": false},"Postmark": {"aliases": ["PostmarkApp"],"host": "smtp.postmarkapp","port": 2525},"qiye.aliyun": {"host": "smtp.mxhichina","port": "465","secure": true},"QQ": {"domains": ["qq"],"host": "smtp.qq","port": 465,"secure": true},"QQex": {"aliases": ["QQ Enterprise"],"domains": ["exmail.qq"],"host": "smtp.exmail.qq","port": 465,"secure": true},"SendCloud": {"host": "smtpcloud.sohu","port": 25},"SendGrid": {"host": "smtp.sendgrid","port": 587},"SendinBlue": {"host": "smtp-relay.sendinblue","port": 587},"SendPulse": {"host": "smtp-pulse","port": 465,"secure": true},"SES": {"host": "email-smtp.us-east-1.amazonaws","port": 465,"secure": true},"SES-US-EAST-1": {"host": "email-smtp.us-east-1.amazonaws","port": 465,"secure": true},"SES-US-WEST-2": {"host": "email-smtp.us-west-2.amazonaws","port": 465,"secure": true},"SES-EU-WEST-1": {"host": "email-smtp.eu-west-1.amazonaws","port": 465,"secure": true},"Sparkpost": {"aliases": ["SparkPost", "SparkPost Mail"],"domains": ["sparkpost"],"host": "smtp.sparkpostmail","port": 587,"secure": false},"Tipimail": {"host": "smtp.tipimail","port": 587},"Yahoo": {"domains": ["yahoo"],"host": "smtp.mail.yahoo","port": 465,"secure": true},"Yandex": {"domains": ["yandex.ru"],"host": "smtp.yandex.ru","port": 465,"secure": true},"Zoho": {"host": "smtp.zoho","port": 465,"secure": true,"authMethod": "LOGIN"},"126": {"host": "smtp.126","port": 465,"secure": true},"163": {"host": "smtp.163","port": 465,"secure": true}
}

 

nodermailer 如果使用自己配置的mail服务:

node_modules/nodemailer/lib/well-known/services.json

需要添加以下内容

   "myservice": {"host": "smtp.myaliyun.club","port": 25,"secure": false}

nodemailer.createTransport 方法调用的时候service选项的值写成 myservice

 

public function test(Request $request) {$mail = new Mail();$mail->mailto = 'xxx@samplehost';$mail->title = 'test smtp.samplehost';$mail->body = 'This is test send';return $mail->send();
}

* Mail.php

<?php
/*** Created by PhpStorm.* User: mingzhanghui* Date: 1/21/2019* Time: 16:16*/namespace App;use App\Jobs\ProcessMail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Queue;class Mail extends Model {protected $table = 'mail';protected $fillable = ['mailto','title','body'];protected $guarded = ['id'];public $timestamps = true;public function send() {// read config from easy_eyes.config$config = new Config();$enabled = $config->get('MAIL_ENABLED');if ($enabled == '0') {Log::info("\033[31memail is disabled\033[0m");return -1; // disabled}$mail_host = $config->get('MAIL_HOST'); $mail_port = $config->get('MAIL_PORT'); $mail_username = $config->get('MAIL_USERNAME'); $mail_password = $config->get('MAIL_PASSWORD'); $mail_from = $config->tryGet('MAIL_FROM', (function() use ($mail_host, $mail_username) {$a = explode('.', $mail_host);$n = count($a);$suffix = sprintf("%s.%s", $a[$n-2], $a[$n-1]);return sprintf("%s@%s", $mail_username, $suffix);})());// create the Transport$transport = (new \Swift_SmtpTransport($mail_host, $mail_port))->setUsername($mail_username)->setPassword($mail_password);// create the Mailer using your created Transport$mailer = new \Swift_Mailer($transport);$emails = $this->mailto;$ea = \explode(';', $emails);$to = [];array_walk($ea, function($e) use (&$to) {$e = trim($e);$a = explode('@', $e);$to[$e] = $a[0];});$message = (new \Swift_Message($this->title))->setFrom([$mail_from => $mail_username])->setTo($to)->setBody($this->body, "text/html", "utf-8");$ret = $mailer->send($message);Log::debug('...email sent');return $ret;}public static function groupComposeAndSend($chunk, $intMinutes, $requestTime) {$title = "";$body = "";self::composeMail($title, $body, $chunk, $intMinutes, $requestTime);// send mail$emails = self::groupSend($title, $body);return $emails;}private static function groupSend($title, $body) {$e = (new Config())->get("GROUP_EMAIL");if (! $e) {return -1;}$emailList = explode(";", $e);$n = 0;foreach ($emailList as $to) {$mail = new Mail();$mail->mailto = $to;$mail->title = $title;$mail->body = $body;$mail->save();Queue::push(new ProcessMail($mail));++$n;Log::info(sprintf("[group report] sending mail to %s", $mail->mailto));}return $n;}/*** @param $title* @param $body* @param $data* @param $intMinutes* @param $requestTime*/private static function composeMail(&$title, &$body, $data, $intMinutes, $requestTime) {$total = count($data);$title = sprintf("EASYEYE接口群监控-请求超过%d秒的接口(%d)", $requestTime, $total);$body = "<style>.text-red {color: red} td {border-collapse: collapse; border: 1px solid #ccc;}</style>";$body .= sprintf("<p>%d分钟内, 搜索到<b class='text-red'>%d</b>条请求接口请求超过%d秒记录: </p>",$intMinutes, $total, $requestTime);$body .= "<table><thead><tr><th>序号</th><th>请求时长(s)</th><th>发生时间戳</th><th>接口URI</th><th>发起请求所在页面URL</th><th>请求内容</th><th>响应码</th></tr></thead><tbody>";foreach ($data as $i => &$item) {$body .= "<tr>";$body .= sprintf("<td>%d</td>", $i + 1);$item['request_time'] = number_format($item['request_time'], 3, '.', '');$body .= sprintf("<td>%s</td>", $item['request_time']);$body .= sprintf("<td>%s</td>", $item['@timestamp']);$body .= sprintf("<td>%s</td>", stripslashes($item['request']));$body .= sprintf("<td>%s</td>", stripslashes($item['referrer']));$body .= sprintf("<td>%s</td>", $item['request_body']);$body .= sprintf("<td>%s</td>", $item['response']);$body .= "</tr>";}$body .= "</tbody></table><br /><br />";}}

* Config.php

<?php
/*** Created by PhpStorm.* User: mingzhanghui* Date: 2018-09-30* Time: 10:36*/namespace App;use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;class Config extends Model
{protected $table = 'config';// table.config + unique(name)protected $fillable = ['name', 'value'];protected $guarded = ['id'];public $timestamps = false;protected $dates = [];public function get($name) {$pairs = DB::table($this->table)->select('value')->where('name', $name)->get();if (count($pairs) === 0) {return "";}$v = $pairs->offsetGet(0);return $v->value;}/*** 配置项可能不存在, 不存在则取默认值, 并在数据库中设定默认值* @param $name* @param $defaultValue* @return mixed*/public function tryGet($name, $defaultValue) {$pairs = DB::table($this->table)->select('value')->where('name', $name)->get();if (count($pairs) === 0) {DB::table($this->table)->insertGetId(['name' => $name,'value' => $defaultValue]);return $defaultValue;}$v = $pairs->offsetGet(0);return $v->value;}public function set($name, $value) {$pairs = DB::table($this->table)->select('id', 'name', 'value')->where('name', $name)->get();// insertif (count($pairs) === 0) {return DB::table($this->table)->insertGetId(['name' => $name,'value' => $value]);}// update (overwrite previous config entries)$id = $pairs->offsetGet($pairs->count() - 1)->id;DB::table($this->table)->where('id', $id)->update(['name' => $name,'value' => $value]);return $id;}
}

 

更多推荐

NodeMailer node.js Send Error: %s' 'self signed certificate'

本文发布于:2024-03-09 10:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1724717.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:js   node   NodeMailer   Send   certificate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!