LoginSignup
4
1

More than 5 years have passed since last update.

Node-RED でメールを送る (POST編)

Last updated at Posted at 2017-08-29

こちらでは、GET でメールを送りましたが、これを POST にしました。
Node-RED でメールを送る

テストプログラムです。
ヘッダーに、application/json を加えました。

server_check_post.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   server_check_post.py
#
#                   Aug/29/2017
# ------------------------------------------------------------------
import sys
import json
import requests

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
mail_to = "aaa_bbb@example.com"
subject = "Node-RED Mail Test Aug/29/2017 AM 09:38"
#
content = ""
content += "おはようございます。\n"
content += "今日は暑くなりそうです。\n"
content += subject + "\n"
#
payload = {
    "to": mail_to,
    "topic": subject,
    "content": content
    }

headers = {'content-type': 'application/json'}
url = "http://127.0.0.1:1880/post_mail"
#
rr=requests.post(url,data=json.dumps(payload),headers=headers)
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 のプログラムです。

post_aug2901.png

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

post_aug2902.png

function ノード

post_aug2903.png

コードです。

node.log ("*** function start ***")
msg.topic = msg.payload.topic
msg.to = msg.payload.to
msg.payload=msg.payload.content
node.log ("*** function end ***")
return msg

http response ノード
e-mail ノード
は、GET と同じです。

4
1
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
4
1