10
7

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-RED でメールを送る

Last updated at Posted at 2017-08-26

Node-RED でメールを送る時に、宛先、タイトル、本文を変数にする方法です。
http://127.0.0.1:1880/mail
に GET で、"to","topic","payload" を与えます。

テストプログラムです。

server_check.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	server_check.py
#
#					Aug/26/2017
# ------------------------------------------------------------------
import sys
import requests

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
mail_to = "aaa_bbb@example.com"
subject = "Node-RED Mail Test Aug/26/2017 PM 20:56"
#
content = ""
content += "こんばんは\n"
content += "今日は暑かった。\n"
content += subject + "\n"
#
args = {
	"to": mail_to,
	"topic": subject,
	"payload": content
	}
url = "http://127.0.0.1:1880/mail"
#
rr=requests.get(url,args)
print(rr)
print(rr.text)
#
#
sys.stderr.write ("mail_to = " + mail_to + "\n")
sys.stderr.write ("subject = " + subject + "\n")
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

Node-RED のプログラムです。

mail_aug2601.png

http in ノード
メソッドは、GET です。

mail_aug2602.png

function ノード

mail_aug2603.png

コードです。

msg.payload=msg.req.query.payload
msg.topic = msg.req.query.topic
msg.to = msg.req.query.to
return msg

http response ノード

mail_aug2604.png

e-mail ノード

Gmail の ユーザID とパスワードを入れます。

mail_aug2605.png

10
7
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
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?