Module: Smitty
- Defined in:
- lib/smitty/croak.rb,
lib/smitty/usage.rb,
lib/smitty/version.rb,
lib/smitty/smtp_connect.rb,
lib/smitty/variable_parser.rb
Constant Summary collapse
- USAGE =
<<DOC Smitty #{Smitty::VERSION} Usage: #{$0} [options] <from_address> <to_file> <subject> <template> #{$0} -h | --help #{$0} -v | --version Required Arguments: from_address: Address to send mail from. to_file: Newline separated file containing recipient addresses. subject: Mail subject, can have handlebar replacements. template: Handlebars like HTML template. Options: -h --help Show this usage. -v --version Show version. --vars key=value,key=value Variables for template and subject line, should be a comma separated list of key value pairs. Key should be the variable name in your template, and value may be a constant or a newline separated file. Value file and to_file must have the same amount of lines. -a files Attach comma separated list of files. --cid Enable CID embedding of images for email attachments, default is false. --server SERVER SMTP Server, default is localhost. --port PORT SMTP Port, default is 25. --ssl Use SSL, default is false. --username USER SMTP user. --password PASSWORD SMTP password. --cc address Add a cc address. --bcc address Add a bcc address. --messageid FQDN Set a FQDN to use when generating the message-id for each message. --sleep SEC Sets sleep delay, in seconds, per each recipent. --dry-run Output messages and don't send. DOC
- VERSION =
'1.0.0'
Class Method Summary collapse
-
.croak(*messages) ⇒ Object
Prints variable amount of messages and exits.
- .smtp_connect(server, port, ssl, username, password) ⇒ Object
- .variable_parser(variable_string, mail_length) ⇒ Object
Class Method Details
.croak(*messages) ⇒ Object
Prints variable amount of messages and exits
3 4 5 6 |
# File 'lib/smitty/croak.rb', line 3 def self.croak(*) .each { || puts "Error: #{}"} exit(1) end |
.smtp_connect(server, port, ssl, username, password) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/smitty/smtp_connect.rb', line 4 def self.smtp_connect(server, port, ssl, username, password) begin smtp_server = server.nil? ? 'localhost' : server smtp_port = port.nil? ? 25 : port.to_i smtp_conn = Net::SMTP.new(smtp_server, smtp_port) smtp_conn.enable_starttls() if ssl if username Smitty.croak('No password provided') if password.nil? if ssl smtp_conn.start(smtp_server, username, password, :login) else smtp_conn.start(smtp_server, username, password, :plain) end else smtp_conn.start() end smtp_conn rescue Exception => e Smitty.croak("Could not connect to SMTP server #{smtp_server}:#{smtp_port}", e.) end end |
.variable_parser(variable_string, mail_length) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/smitty/variable_parser.rb', line 2 def self.variable_parser(variable_string, mail_length) pairs = variable_string.split('=') # content is a file begin with_content = File.readlines(pairs[1]).map(&:chomp) Smitty.croak("#{pairs[0]} != recipient length") if with_content.length != mail_length rescue Errno::ENOENT with_content = pairs[1] rescue croak("Could not parse key value pair #{variable_string}") end {replace_string: pairs[0], with: with_content } end |