Object
Emailer class makes it easy send out an email.
Settings:
subject Subject of email message. from Message FROM address [email]. to Email address to send announcemnt. server Email server to route message. port Email server's port. port_secure Email server's port. domain Email server's domain name. account Email account name if needed. password Password for login.. login Login type: plain, cram_md5 or login [plain]. secure Uses TLS security, true or false? [false] message Mesage to send -or- file File that contains message.
# File lib/syckle/shell/email.rb, line 60 def environment_options options = {} options[:server] = ENV['EMAIL_SERVER'] options[:from] = ENV['EMAIL_FROM'] options[:account] = ENV['EMAIL_ACCOUNT'] || ENV['EMAIL_FROM'] options[:password] = ENV['EMAIL_PASSWORD'] options[:port] = ENV['EMAIL_PORT'] options[:domain] = ENV['EMAIL_DOMAIN'] options[:login] = ENV['EMAIL_LOGIN'] options[:secure] = ENV['EMAIL_SECURE'] options end
# File lib/syckle/shell/email.rb, line 94 def initialize(options={}) require_smtp options = options.rekey if not options[:server] options = self.class.environment_options.merge(options) end @mailto = options[:to] || options[:mailto] @from = options[:from] @message = options[:message] @subject = options[:subject] @server = options[:server] @account = options[:account] @passwd = options[:password] @login = options[:login] @secure = options[:secure] #.to_b @domain = options[:domain] @port = options[:port] @port ||= secure ? 465 : 25 @port = @port.to_i @account ||= @from @login ||= :plain @login = @login.to_sym @passwd ||= self.class.password @domain ||= @server # save the password for later use self.class.password = @passwd end
# File lib/syckle/shell/email.rb, line 134 def email(options={}) options.rekey message = options[:message] || self.message subject = options[:subject] || self.subject from = options[:from] || self.from mailto = options[:mailto] || options[:to] || self.mailto raise ArgumentError, "missing email field -- server" unless server raise ArgumentError, "missing email field -- account" unless account raise ArgumentError, "missing email field -- from" unless from raise ArgumentError, "missing email field -- mailto" unless mailto raise ArgumentError, "missing email field -- subject" unless subject passwd ||= password("#{account} password:") mailto = [mailto].flatten.compact msg = "" msg << "From: #{from}\n" msg << "To: #{mailto.join(';')}\n" msg << "Subject: #{subject}\n" msg << "" msg << message #p server, port, domain, account, passwd, login, secure if verbose? begin if Net::SMTP.respond_to?(:enable_tls) && secure Net::SMTP.enable_tls Net::SMTP.start(server, port, domain, account, passwd, login, secure) do |smtp| smtp.send_message(msg, from, mailto) end else Net::SMTP.start(server, port, domain, account, passwd, login) do |smtp| smtp.send_message(msg, from, mailto) end end return mailto rescue Exception => e return e end end
Ask for a password.
FIXME: Does not hide password.
# File lib/syckle/shell/email.rb, line 183 def password(msg=nil) msg ||= "Enter Password: " inp = '' $stdout << msg inp = STDIN.gets.chomp #begin # system "stty -echo" # inp = gets.chomp #ensure # system "stty echo" #end return inp end
Generated with the Darkfish Rdoc Generator 2.