Module: OnlyofficeIredmailHelper::SendMessageMethods

Included in:
IredMailHelper
Defined in:
lib/onlyoffice_iredmail_helper/send_message_methods.rb

Overview

Methods to send message

Instance Method Summary collapse

Instance Method Details

#create_msg(msg_data = {}) ⇒ String

Form a email string

Parameters:

  • msg_data (Hash) (defaults to: {})

    params

Returns:

  • (String)

    formed mail message



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/onlyoffice_iredmail_helper/send_message_methods.rb', line 9

def create_msg(msg_data = {})
  <<~END_OF_MESSAGE
    From: #{@username}
    To: #{msg_data[:mailto]}
    Subject: #{msg_data[:subject]}
    Date: #{Time.now.rfc2822}
    Message-Id: "#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@#{@username.split('@').last}"
    
    #{msg_data[:body]}
  END_OF_MESSAGE
end

#send_mail(options = {}) ⇒ nil

Send mail

Parameters:

  • options (Hash) (defaults to: {})

    hash with params

Returns:

  • (nil)


24
25
26
27
28
29
30
31
# File 'lib/onlyoffice_iredmail_helper/send_message_methods.rb', line 24

def send_mail(options = {})
  options[:subject] ||= @default_subject
  options[:body] ||= @default_body
  options[:mailto] ||= @default_user
  smtp = Net::SMTP.start(@domainname, 25, @username, @username, @password, :login)
  smtp.send_message create_msg(options), @username, options[:mailto]
  smtp.finish
end