Sha256: 1dfde5e02513233885ac69c9377cb67dd8ab5dd06f48ccb655674d96e73f76f5
Contents?: true
Size: 1.41 KB
Versions: 12
Compression:
Stored size: 1.41 KB
Contents
#!/usr/bin/env ruby require 'thor' require 'mail' require 'cknife/config' class CKnifeEmail < Thor no_tasks do def config @config ||= CKnife::Config end end desc "mail [RECIPIENT] [SUBJECT] [TEXT_FILE]", "Send an email to recipient." method_options :from => "" method_options :simple_format => true def mail(recipient, subject, text_file) smtp_settings = { :address => config['mail.address'], :port => config['mail.port'] || 587, :domain => config['mail.domain'], :authentication => config['mail.authentication'].to_sym, :user_name => config['mail.username'], :password => config['mail.password'], :enable_starttls_auto => true } Mail.defaults do delivery_method :smtp, smtp_settings end from = !options[:from].blank? ? options[:from] : config['mail.from'] if from.blank? say("No from address found. No action taken.") return end body = File.read(text_file) body_html = options[:simple_format] ? CKnife::Formatter.new.simple_format(body) : nil mail = Mail.new do from from to recipient subject subject body body if body_html html_part do content_type 'text/html; charset=UTF-8' body body_html end end end mail.deliver say("Mail delivered to #{recipient}.") end end CKnifeEmail.start
Version data entries
12 entries across 12 versions & 1 rubygems