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



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 = {})
  "    From: \#{@username}\n    To: \#{msg_data[:mailto]}\n    Subject: \#{msg_data[:subject]}\n    Date: \#{Time.now.rfc2822}\n    Message-Id: \"\#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@\#{@username.split('@').last}\"\n    \n    \#{msg_data[:body]}\n  END_OF_MESSAGE\nend\n"

#send_mail(options = {}) ⇒ nil

Send mail



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