Created
August 9, 2010 12:32
-
-
Save ayosec/515353 to your computer and use it in GitHub Desktop.
Simple script to auto-reply mails
This file contains 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
from: [email protected] | |
body: "Invalid mail" | |
include_source: true | |
This file contains 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
#!/usr/bin/ruby | |
require 'tmail' | |
require 'yaml' | |
require 'net/smtp' | |
config = YAML.load(File.read(ARGV.first || "/etc/mail-autoreply.yml")) | |
raw_mail = STDIN.read | |
mail = TMail::Mail.parse(raw_mail) | |
if mail.from.first == config["from"] | |
# Ignore "self" emails | |
exit 0 | |
end | |
response = TMail::Mail.new | |
response.subject = config["subject"] || "Re: #{mail.subject}" | |
response.from = config["from"] | |
response.to = mail.from.first | |
response.in_reply_to = mail.message_id | |
response.disposition = "inline" | |
response.date = Time.now | |
body = TMail::Mail.new | |
body.content_type = "text/plain; charset=UTF-8" | |
body.body = config["body"] | |
body.disposition = "inline" | |
response.parts << body | |
if config["include_source"] | |
original_mail = TMail::Mail.new | |
original_mail.content_type = "message/rfc822" | |
original_mail.body = raw_mail.sub(/\AFrom .*?$/, '').sub(/\A\s+/, '') | |
original_mail.disposition = "inline" | |
response.parts << original_mail | |
end | |
Net::SMTP.start('localhost', 25) do |smtp| | |
smtp.send_message response.to_s, response.from, response.to | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment