Created
September 4, 2017 06:30
-
-
Save masakuni-ito/3fe77067e94d228e26425df75691c923 to your computer and use it in GitHub Desktop.
hubot用RTMメール送信
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| child_process = require 'child_process' | |
| module.exports = (robot) -> | |
| sendEmail = (to, subject, msg, from, recipients='') -> | |
| mailArgs = ['-s', subject, '-r', "#{from}", '-S', "From: #{from}", "#{to}"] | |
| mailArgs = mailArgs.concat recipients | |
| p = child_process.execFile '/usr/bin/mail', mailArgs, {}, (error, stdout, stderr) -> | |
| console.log 'stdout: ' + stdout | |
| console.log 'stderr: ' + stderr | |
| p.stdin.write "#{msg}\n" | |
| p.stdin.end() | |
| robot.hear /@rtm/, (msg) -> | |
| title = '' | |
| note = '' | |
| tmp = msg.message.text.replace(/@rtm/, '').trim() | |
| tmp = " " + tmp + "\n " | |
| body = tmp.match(/^(.*?)\n([\s\S]*)$/) | |
| if body[1] | |
| title = body[1].trim() | |
| if body[2] | |
| note = body[2].trim() | |
| if !title | |
| msg.send "no title...." | |
| return | |
| # send | |
| sendEmail process.env.HUBOT_RTM_MAIL, title, note, process.env.HUBOT_RTM_FROM | |
| msg.send "I sent mail to Bob!\nHe is fine!\n\n*title*: #{title}\n*note*:\n#{note}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment