def send_email(recipient, subject, message)
sender = Email.options.sender_full || "#{Email.options.sender} <#{Email.options.sender}>"
subject = [Email.options.subject_prefix, subject].join(' ').strip
id = Email.options.generator.call
email = [
"From: #{sender}", "To: <#{recipient}>", "Date: #{Time.now.rfc2822}",
"Subject: #{subject}", "Message-Id: #{id}", '', message
].join(Email.options.newline)
email_options = []
[:host, :port, :helo_domain, :username, :password, :auth_type].each do |k|
email_options.push(Email.options[k])
end
begin
Net::SMTP.start(*email_options) do |smtp|
smtp.send_message(
email,
Email.options.sender,
[recipient, *Email.options.bcc]
)
Ramaze::Log.info(
"Email sent to #{recipient} with subject \"#{subject}\""
)
end
rescue => e
Ramaze::Log.error(
"Failed to send an Email to #{recipient}: #{e.inspect}"
)
end
end