Created
May 20, 2021 13:46
-
-
Save jeremysmithco/52db4d5d1e0b15e4969c4bb8a0087480 to your computer and use it in GitHub Desktop.
Rails bin script to listen for emails delivered to filesystem and open with Mail (on a Mac)
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
#!/usr/bin/env ruby | |
require 'listen' | |
APP_ROOT = File.expand_path('..', __dir__) | |
listener = Listen.to("#{APP_ROOT}/tmp/mails") do |_modified, added, _removed| | |
added.each do |added_file| | |
if added_file.end_with?(".eml") | |
system("open -a Mail #{added_file}") | |
else | |
File.rename(added_file, "#{added_file}-#{Time.now.to_i}.eml") | |
end | |
end | |
end | |
listener.start | |
sleep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ActionMailer relies on the
mail
gem to deliver emails to the filesystem, andmail
'sFileDelivery#deliver!
method names those files the destination email address. So this script first renames the file appending a timestamp and.eml
extension, then opens the renamed file.