XioNoX
(XioNoX)
2014 年6 月 25 日 20:24
1
Hi!
To be able to sort automatically notification emails sent by Discourse, it would be great if they could have customs headers (or a subject tag) based on the message’s content/content:
For example, here is a list of headers Bugzilla sends with each notification email:
X-Bugzilla-Reason: CC AssignedTo
X-Bugzilla-Type: dep_changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Classification: Other
X-Bugzilla-ID: 1014331
X-Bugzilla-Product: mozilla.org
X-Bugzilla-Component: Server Operations
X-Bugzilla-Version: other
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: foobar@email.com
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: FIXED
X-Bugzilla-Priority: –
X-Bugzilla-Assigned-To: email@email.com
X-Bugzilla-Target-Milestone: —
X-Bugzilla-Flags:
X-Bugzilla-OS: Linux
X-Bugzilla-Changed-Fields: Status Resolution
X-Bugzilla-Changed-Field-Names: bug_status resolution
Thanks!
3 个赞
downey
(Michael Downey)
2014 年6 月 25 日 20:55
2
See also our discussion at:
As a standard Discourse user, I want to see standardized indication of the category assigned to a post when I receive e-mail notifications, so I can better prioritize what I reply to and when.
Rationale: We’re working really hard to migrate people from a series of several mailing lists over to Discourse, and being able to specify categories in notifications somehow is pretty important to attracting those people who still want to live in their inbox. If the category were specified in the subject…
Where we’re hoping to get categories in a header.
downey
(Michael Downey)
2014 年10 月 9 日 20:05
3
FYI, there is now a category-specific List-Id header sent along with unsubscribe headers, and the ability to add your own generic headers for all notifications with the email custom headers site setting.
2 个赞
For those who are wondering how to set the custom email header, here it is.
Go to your Settings Panel >> Email or use below link
https://forums.example.com/admin/site_settings/category/email, you should replace the domain name with your own.
Search for email custom headers, and set your own. That’s it!
mattdm
(Matthew Miller)
2020 年12 月 17 日 23:38
5
Can formatting things like %{optional_pm}%{optional_cat}%{topic_title} go in the custom headers?
1 个赞
mattdm
(Matthew Miller)
2022 年1 月 5 日 19:55
6
就我所知,我刚刚测试过,答案是:不行,没有扩展。我得到例如
X-Tags: %{optional_tags}
1 个赞
simon
2022 年1 月 8 日 01:03
7
我没有在代码的任何地方看到类似 %{optional_tags} 的内容会被替换到 email custom headers 站点设置中添加的标头里。我发现的是这个用于设置自定义标头值的方法:
SiteSetting.secure_uploads_max_email_embed_image_size_kb.kilobytes
return
end
true
end
#
# Two behaviors in the mail gem collide:
#
# 1. Attachments are added as extra parts at the top level,
# 2. When there are both text and html parts, the content type is set
# to 'multipart/alternative'.
#
# Since attachments aren't alternative renderings, for emails that contain
# attachments and both html and text parts, some coercing is necessary.
#
# When there are alternative rendering and attachments, this method causes
# the top level to be 'multipart/mixed' and puts the html and text parts
# into a nested 'multipart/alternative' part.
#
# Due to mail gem magic, @message.text_part and @message.html_part still
它被调用自:
# to the array of values for the header.
@message.header[key] = nil
@message.header[key] = our_value
end
value = header_value(key)
# Remove Auto-Submitted header for group private message emails, it does
# not make sense there and may hurt deliverability.
#
# From https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml:
#
# > Indicates that a message was generated by an automatic process, and is not a direct response to another message.
@message.header[key] = nil if key.downcase == "auto-submitted" && smtp_group_id
# Replace reply_key in custom headers or remove
if value&.include?("%{reply_key}")
# Delete old header first or else the same header will be added twice
@message.header[key] = nil
@message.header[key] = value.gsub!("%{reply_key}", reply_key) if reply_key.present?
end
我将尝试从 Discourse 团队获取更多关于该设置预期用途以及可以替换到自定义标头中的值的详细信息。
mattdm
(Matthew Miller)
2022 年1 月 8 日 16:31
8
@simon 比较
# No point in adding a reply-to header if it is going to be identical
# to the from address/alias. If the from option is not present, then
# the default reply-to address is used.
result['Reply-To'] = from_value if from_value != alias_email(@opts[:from])
end
end
result.merge(MessageBuilder.custom_headers(SiteSetting.email_custom_headers))
end
def self.custom_headers(string)
result = {}
string.split('|').each { |item|
header = item.split(':', 2)
if header.length == 2
name = header[0].strip
value = header[1].strip
result[name] = value if name.length > 0 && value.length > 0
end
} unless string.nil?
result
和
elsif SiteSetting.unsubscribe_via_email_footer
"unsubscribe_link_and_mail"
else
"unsubscribe_link"
end
@template_args[:unsubscribe_instructions] = I18n.t(unsubscribe_string, @template_args)
end
end
end
def subject
if @opts[:template] &&
TranslationOverride.exists?(locale: I18n.locale, translation_key: "#{@opts[:template]}.subject_template")
augmented_template_args = @template_args.merge({
site_name: @template_args[:email_prefix],
optional_re: @opts[:add_re_to_subject] ? I18n.t('subject_re') : '',
optional_pm: @opts[:private_reply] ? @template_args[:subject_pm] : '',
optional_cat: @template_args[:show_category_in_subject] ? "[#{@template_args[:show_category_in_subject]}] " : '',
optional_tags: @template_args[:show_tags_in_subject] ? "#{@template_args[:show_tags_in_subject]} " : '',
topic_title: @template_args[:topic_title] ? @template_args[:topic_title] : '',
})
模板和 email_subject 设置之间存在一些复杂性,我不太明白——看起来如果存在模板,后者就不会被使用,但我不确定没有模板时会怎样!但除此之外,基本情况是,如果构建自定义标头的函数使用了相同的模板,这将起作用,并且自定义标头可以包含有用的动态信息。
2 个赞