Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mail template param #2881

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/mailers/system_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ def send_message(options)

mail_options = { to: options[:to], subject: options[:subject] }
mail_options[:from] = options[:from] if options[:from].present?

template = options[:template] if options[:template].present?

if options[:content_type].present?
mail(mail_options) do |format|
format.text if options[:content_type] == "text/plain"
format.html if options[:content_type] == "text/html"
format.text { render template } if options[:content_type] == "text/plain"
format.html { render template } if options[:content_type] == "text/html"
end
else
mail(mail_options)
Expand Down
4 changes: 4 additions & 0 deletions app/models/agents/email_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class EmailAgent < Agent
You can provide a `content_type` for the email and specify `text/plain` or `text/html` to be sent.
If you do not specify `content_type`, then the recipient email server will determine the correct rendering.

For more complex message formatting, if you specify a `content_type` then you can also provide an alternate message `template` name. A user-defined
`template` matching the name which must be located in `'../huginn/app/views/system_mailer'` as `<template_name>.html.erb` or `<template_name>.text.erb`.

Set `expected_receive_period_in_days` to the maximum amount of time that you'd expect to pass between Events being received by this Agent.
MD

Expand All @@ -54,6 +57,7 @@ def receive(incoming_events)
headline: interpolated(event)['headline'],
body: interpolated(event)['body'],
content_type: interpolated(event)['content_type'],
template: interpolated(event)['template'],
groups: [present(event.payload)]
).deliver_now
log "Sent mail to #{recipient} with event #{event.id}"
Expand Down