Method: EmailHelper#send_email
- Defined in:
- lib/helpers/tmc_helpers/email_helper/email_helper.rb
#send_email(subject, body, to, endpoint: nil, username: nil, password: nil) ⇒ Object
Public: Sends an email.
subject - String email subject. body - String email message body. to - String or Array of String recipient email addresses. endpoint - String EWS endpoint URL (default: nil). username - String EWS account username (default: nil). password - String EWS account password (default: nil).
Returns nothing.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/helpers/tmc_helpers/email_helper/email_helper.rb', line 19 def send_email(subject, body, to, endpoint: nil, username: nil, password: nil) logger.debug(%Q(Sending email to #{to} with subject "#{subject}" [#{body.length} chars])) @spam_sleep = @last_email_time.nil? ? 0 : 60 - (Time.now - @last_email_time) if @spam_sleep > 0 sleep(@spam_sleep.to_i.sec) end with_ews_client(endpoint, username, password) do |cli| cli. do |m| m.subject = subject m.body = body if to.is_a?(Array) to.each {|r| m.to_recipients << r} else m.to_recipients << to end end @last_email_time = Time.now end end |