21
30

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.

Node.jsにてSMTPサーバなしでメール送信

Last updated at Posted at 2019-09-07

#はじめに
普段の送信ではSMTPサーバを利用して送信しますが、SMTPサーバをない状態で送信したい場合があります。
Node.jsではnode-sendmailというモジュールを利用すると簡単にできます。

#node-sendmailとは
Send mail without SMTP server
URL: http://github.com/guileen/node-sendmail

#インストール
npm install sendmail --save

#メール送信例

const sendmail = require('sendmail')();
 
sendmail({
    from: 'xxx@yyy.com',
    to: 'user1@xxx.com, user2@yyy.com',
    subject: 'メールのタイトルです',
    text: 'メールの本文です。この例はテキストです。html形式でもOK。',
  }, function(err, reply) {
    console.log(err && err.stack);
    console.dir(reply);
});

#設定可能なオプション
from
sender
to
cc
bcc
replyTo
inReplyTo
subject
text
html

#添付ファイルの例
https://github.com/guileen/node-sendmail/blob/master/examples/attachmentFile.js

以上

21
30
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
21
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?