Help us understand the problem. What is going on with this article?

Node.jsでメールを送信するパッケージ

More than 5 years have passed since last update.

nodemailer npm公式サイト
http://www.nodemailer.com/

nodemailer npmパッケージサイト
https://npmjs.org/package/nodemailer

nodemailer GitHubサイト
https://github.com/andris9/nodemailer

SMTPに使用できるメールサービス

  • DynectEmail
  • Gmail
  • hot.ee
  • Hotmail
  • iCloud
  • mail.ee
  • Mail.Ru
  • Mailgun
  • Mailjet
  • Mandrill
  • Postmark
  • QQ
  • QQex (Tencent Business Email)
  • SendGrid
  • SendCloud
  • SES
  • Yahoo
  • yandex
  • Zoho

インストール

npm install nodemailer

サンプルコード

var mailer = require('nodemailer');

//SMTPの設定
var setting = {
    //SMTPサーバーを使う場合
    host: 'SMTPホスト',
    auth: {
        user: 'ユーザ名',
        pass: 'パスワード',
        port: 'SMTPポート番号'
    }

    /*
    //Webサービスを使う場合
    service: 'サービス名', //'Gmail'、'Hotmail'、'Yahoo Mail'など
    auth: {
        user: 'アカンと名',
        pass: 'パスワード',
        port: 'ポート番号' //'25'など
    }
    */
};

//メールの内容
var mailOptions = {
    from: '送信者のメールアドレス',
    to: '送信先メールアドレス',
    subject: 'メールの件名',
    html: 'メールの内容' //HTMLタグが使えます
};

//SMTPの接続
var smtp = mailer.createTransport('SMTP', setting);

//メールの送信
smtp.sendMail(mailOptions, function(err, res){
    //送信に失敗したとき
    if(err){
        console.log(err);
    //送信に成功したとき
    }else{
        console.log('Message sent: ' + res.message);
    }
    //SMTPの切断
    smtp.close();
});
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした