36
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

速攻NodeJSで簡単メール送信

Posted at

NodeJSでメール送信

環境

  • モジュールはnodemailerを使用します。
  • SMTPはGメールを使用します。

ソース

mail.js
var receiverEmailAddress = '{宛先アドレス}@*****.com'
var senderEmailAddress = '{作成したGメール}@gmail.com'
var senderEmailPassword = '{作成したGメールアカウントのパスワード}'

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
  host: 'smtp.gmail.com',
  port: 465,
  secure: true, // SSL
  auth: {
    user: senderEmailAddress,
    pass: senderEmailPassword
  }
});
var mailOptions1 = {
  from: senderEmailAddress,
  to: receiverEmailAddress,
  subject: '{件名}',
  text: '{本文}'
};
transporter.sendMail(mailOptions1, function (error, info) {
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

使用方法

  1. モジュールのインストールnpm install nodemailer
  2. スクリプト実行node mail.js

結果

Email sent: 250 2.0.0 OK ******* f11sm5251981pfd.27 - gsmtp

36
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?