Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hubot用RTMメール送信
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
You can’t perform that action at this time.