Class: CliApplication::MailLib::Sendmail

Inherits:
Base
  • Object
show all
Defined in:
lib/cli_application/mail_lib/sendmail.rb

Instance Attribute Summary

Attributes inherited from Base

#config_fail_message, #delivery_method

Instance Method Summary collapse

Methods inherited from Base

#address, #authentication, #domain, #log_filename, #password, #port, #smpt_log?, #tls?, #user_name, #valid?

Constructor Details

#initialize(config, folders) ⇒ Sendmail

:nodoc:



7
8
9
10
11
12
# File 'lib/cli_application/mail_lib/sendmail.rb', line 7

def initialize(config, folders) # :nodoc:
  @delivery_method = :sendmail
  super(config, folders)

  check_config
end

Instance Method Details

#sendmail_argumentsString

Метод возаращает опции ‘sendmail’

Returns:

  • (String)

    опции ‘sendmail’



49
50
51
# File 'lib/cli_application/mail_lib/sendmail.rb', line 49

def sendmail_arguments
  @config.sendmail.arguments
end

#sendmail_locationString

Метод возвращает путь к скрипту ‘sendmail’

Returns:

  • (String)

    путь к скрипту ‘sendmail’



42
43
44
# File 'lib/cli_application/mail_lib/sendmail.rb', line 42

def sendmail_location
  @config.sendmail.location
end

#simple_send(to, name, title, body) ⇒ Boolean

Метод отправки электронного сообщения через sendmail

Parameters:

  • to (String)

    электронная почта лица, которому отправляется сообщение, или массив адресов

  • name (String)

    имя клиента, которому отправляется сообщение

  • title (String)

    заголовок письма

  • body (String)

    текст письма

Returns:

  • (Boolean)

    true, если письмо помещено в очередь сообщений sendmail



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cli_application/mail_lib/sendmail.rb', line 21

def simple_send(to, name, title, body)
  return false unless valid?

  message = CliApplication::MailLib::Message.new
  message.from_email = @config.from
  message.subject = title
  message.body = (@config.footer.nil? || @config.footer == '') ? body : (body+@config.footer)
  processing_to(to, name, message)

  begin
    send_message(message)
    true
  rescue Exception => e
    $stderr.puts "Ошибка отправки письма: #{e.message}"
    false
  end
end