node.js는 nodemailer를 사용하여 이메일 예제를 보냅니다.

高洛峰
풀어 주다: 2016-12-17 12:55:54
원래의
1688명이 탐색했습니다.

1. nodemailer 설치

npm install nodemailer --save

2.

var nodemailer = require("nodemailer");
// 开启一个 SMTP 连接池
var smtpTransport = nodemailer.createTransport("SMTP",{
  host: "smtp.qq.com", // 主机
  secureConnection: true, // 使用 SSL
  port: 465, // SMTP 端口
  auth: {
    user: "xxxxxxxx@qq.com", // 账号
    pass: "xxxxxxxx" // 密码
  }
});
// 设置邮件内容
var mailOptions = {
  from: "Fred Foo <xxxxxxxx@qq.com>", // 发件地址
  to: "2838890xx@qq.com, minimixx@126.com", // 收件列表
  subject: "Hello world", // 标题
  html: "<b>thanks a for visiting!</b> 世界,你好!" // html 内容
}
// 发送邮件
smtpTransport.sendMail(mailOptions, function(error, response){
  if(error){
    console.log(error);
  }else{
    console.log("Message sent: " + response.message);
  }
  smtpTransport.close(); // 如果没用,关闭连接池
});
로그인 후 복사

호출3. 오류 원인: 계정에 서비스가 설정되어 있지 않습니다

해결책: QQ 메일-> 설정-> 서비스 활성화: POP3/SMTP 서비스
{ [AuthError: Invalid login - 454 Authentication failed, please open smtp flag first!]
  name: &#39;AuthError&#39;,
  data: &#39;454 Authentication failed, please open smtp flag first!&#39;,
  stage: &#39;auth&#39; }
로그인 후 복사


오류: 보내는 계정이 같습니다. 인증 계정이 다릅니다.

{ [SenderError: Mail from command failed - 501 mail from address must be same as authorization user]
  name: &#39;SenderError&#39;,
  data: &#39;501 mail from address must be same as authorization user&#39;,
  stage: &#39;mail&#39; }
로그인 후 복사


노드 메일러를 사용하여 이메일을 보내고 관련 기사는 PHP 중국어 웹사이트를 주목해주세요!

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!