class Hyla::Commands::Sendmail
Public Class Methods
inline_body_with_attachments(html, attachments)
click to toggle source
Substitute filename with cid
# File lib/hyla/commands/sendmail.rb, line 112 def self.inline_body_with_attachments(html, attachments) attachments.each do |attachment| if (html =~ /#{attachment.filename}/) html = html.sub(attachment.filename, "cid:#{attachment.cid}") end end return html end
parameters()
click to toggle source
Generate
the Hash
of the parameters used by mail component nto send email
# File lib/hyla/commands/sendmail.rb, line 98 def self.parameters() parameters = {} parameters[:address] = @smtp_server unless @smtp_server.nil? parameters[:port] = @port_number unless @port_number.nil? parameters[:enable_starttls] = @enable_starttls unless @enable_starttls.nil? parameters[:user_name] = @user unless @user.nil? parameters[:password] = @password unless @password.nil? parameters[:authentication] = @authentication unless @authentication.nil? return parameters end
populate_email(recipients, sender, subject)
click to toggle source
Create Mail using Recipients, Sender and subject
# File lib/hyla/commands/sendmail.rb, line 84 def self.populate_email(recipients, sender, subject) mail = Mail.new do to recipients from sender subject subject content_type 'multipart/related' end return mail end
process(args, options)
click to toggle source
# File lib/hyla/commands/sendmail.rb, line 5 def self.process(args, options) location = options[:source] if self.check_mandatory_option?('-s / --source', options[:source]) file_name = options[:file] if check_mandatory_option?('-f / --file', options[:file]) email_attributes = options[:email_attributes] if check_mandatory_option?('-e / --email_attributes', options[:email_attributes]) attachment = options[:attachment] sender = email_attributes[:from] recipients = email_attributes[:to] subject = email_attributes[:subject] file_path = [location, file_name] * '/' # Parameters used to connect to the SMTP Server @smtp_server = email_attributes[:smtp_server] if check_mandatory_option?(':smtp_server not defined in _config.yaml file', email_attributes[:smtp_server]) @port_number = email_attributes[:port] if check_mandatory_option?(':port not defined in _config.yaml file', email_attributes[:port]) @user = email_attributes[:user] @password = email_attributes[:password] @authentication = email_attributes[:authentication] @enable_starttls = email_attributes[:enable_starttls] if check_mandatory_option?(':enable_start_tls not defined in _config.yaml file', email_attributes[:enable_starttls]) body = <<-EOS <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>REPORT</title> <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/foundation/5.0.3/css/foundation.min.css" /> <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.3/normalize.min.css" /> </head> <body> <div class="row"> <!-- Main Content --> <div class="large-9 columns" role="content"> <article> <h4>#{subject}</h4> <p>Attached as <a href=\'#{file_name}'>HTML file to this email</a></p> <p>Generated by Hyla Tool</p> </p> <p>Remark : html Link works with Thunderbird, Gmail clients but not using Zimbra Web Client</p> </article> </div> </div> </body> </html> EOS mail = populate_email(recipients, sender, subject) case attachment when true attachment = File.read(file_path) mail.attachments[file_name] = { :mime_type => 'application/x-html', :content => attachment, :Content_Transfer_Encoding => 'quoted-printable'} inline_html = inline_body_with_attachments(body, mail.attachments) when false inline_html = File.read(file_path) end html_part = Mail::Part.new do content_type 'text/html; charset=UTF-8' content_transfer_encoding 'quoted-printable' body inline_html end mail.html_part = html_part mail.delivery_method :smtp, parameters() mail.deliver! Hyla.logger2.info "Email send to SMTP server from #{sender} with this subject : #{subject}" end