接收电子邮件¶
- 目录
- 接收电子邮件
Redmine可以被配置为允许通过电子邮件创建问题或发表评论。它还可以识别并合并对论坛消息的电子邮件回复。
设置¶
您可以通过以下方式之一配置Redmine接收电子邮件:
- 从您的邮件服务器转发电子邮件
- 优点:与远程邮件服务器兼容,电子邮件即时处理,速度快(无需重新加载环境)
- 缺点:需要在您的邮件传输代理(例如Postfix,Sendmail...)上做一些配置
- 从IMAP或POP3服务器获取电子邮件
- 优点:易于设置,无需配置您的MTA,与远程邮件服务器兼容
- 缺点:电子邮件不是即时处理的(需要添加cron作业定期读取电子邮件)
- 从标准输入读取电子邮件
- 优点:适合测试目的
- 缺点:速度慢(每次读取电子邮件时都会重新加载环境),需要在您的MTA上做一些配置
从您的邮件服务器转发电子邮件¶
可以使用独立脚本来转发来自您的邮件服务器的传入电子邮件。
此脚本从标准输入读取原始电子邮件并将其通过HTTP请求转发到Redmine。
它位于您的redmine目录中:extra/mail_handler/rdm-mailhandler.rb。
为了使用它,您必须启用接收电子邮件的API
转到 应用程序设置 -> 传入电子邮件,勾选 启用传入电子邮件的WS 并输入或生成一个密钥。
将 rdm-mailhandler.rb 复制到您的邮件服务器,确保其权限允许执行(chmod +x rdm-mailhandler.rb),并配置您的MTA(邮件传输代理)。
用法
Usage: rdm-mailhandler.rb [options] --url=<Redmine URL> --key=<API key>
Required arguments:
-u, --url URL URL of the Redmine server
-k, --key KEY Redmine API key
General options:
--key-file FILE full path to a file that contains your Redmine
API key (use this option instead of --key if
you don't want the key to appear in the command
line)
--no-check-certificate do not check server certificate
--certificate-bundle FILE
certificate bundle to use
-h, --help show this help
-v, --verbose show extra information
-V, --version show version information and exit
User and permissions options:
--unknown-user ACTION how to handle emails from an unknown user
ACTION can be one of the following values:
* ignore: email is ignored (default)
* accept: accept as anonymous user
* create: create a user account
--no-permission-check disable permission checking when receiving
the email
--default-group GROUP add created user to GROUP (none by default)
GROUP can be a comma separated list of groups
--no-account-notice don't send account information to the newly
created user
--no-notification disable email notifications for the created
user
Issue attributes control options:
--project-from-subaddress ADDR
select project from subaddress of ADDR found
in To, Cc, Bcc headers
-p, --project PROJECT identifier of the target project
-s, --status STATUS name of the target status
-t, --tracker TRACKER name of the target tracker
--category CATEGORY name of the target category
--priority PRIORITY name of the target priority
--assigned-to ASSIGNEE assignee (username or group name)
--fixed-version VERSION name of the target version
--private create new issues as private
-o, --allow-override ATTRS allow email content to set attributes values
ATTRS is a comma separated list of attributes
or 'all' to allow all attributes to be
overridable (see below for details)
有关可用于 --allow-override 选项的值的列表,请参阅 问题属性。
示例
# No project specified. Emails MUST contain the 'Project' keyword:
rdm-mailhandler.rb --url http://redmine.domain.foo --key secret
# Fixed project and default tracker specified, but emails can override
# both tracker and priority attributes:
rdm-mailhandler.rb --url https://domain.foo/redmine --key secret \\
--project foo \\
--tracker bug \\
--allow-override tracker,priority
以下是一个Postfix本地别名条目的示例
foo: "|/path/to/rdm-mailhandler.rb --url http://redmine.domain --key secret --project foo"
此行应放在别名文件中,该文件通常在 /etc/aliases 中指定。如果位置未知,请使用命令 postconf alias_maps 来查找。更新别名文件后,请务必运行 newaliases 以通知Postfix新条目。
如果您的域名已配置为虚拟邮箱映射(因此您使用 /etc/postfix/virtual_mailbox_maps 来执行形式为 user@example.com /path/example.com/user 的映射),则应该
- 在
/etc/virtual中创建一个映射,如下所示:foo@example.org foo - 修改
/etc/postfix/main.cf以指定传输文件:transport_maps = hash:/etc/postfix/transport - 在传输文件中添加类似的一行:
foo@example.org local:
说明: - 当您为某个域名定义虚拟邮箱映射时,默认传输方式是虚拟的,这意味着在 /etc/postfix/virtual 中指定本地别名将失败(显示“未知用户”)。为了解决这个问题,我们通过指定特定邮箱的本地传输来覆盖默认传输方式,这意味着本地别名可以正确解析,并且您的脚本将被执行。
从 IMAP 服务器获取邮件¶
可以使用一个 rake 任务(redmine:email:receive_imap)来从 IMAP 服务器获取传入的邮件。当您从 cron 作业运行 rake 命令时,可以在 rake 命令中包含开关 -f /path/to/redmine/appdir/Rakefile,因为否则 rakefile 将找不到。以下是一个 cron 文件示例行,每 30 分钟获取一次邮件
*/30 * * * * redmineuser rake -f /path/to/redmine/appdir/Rakefile redmine:email:receive_imap RAILS_ENV="production" host=imap.foo.bar username=redmine@somenet.foo password=xxx
如果您的设置正常工作,但您收到来自 cron 守护进程的邮件,可以通过添加 --silent 开关来抑制 rake 命令的输出。这应该会停止 cron 在命令每次执行时发送邮件。
*/30 * * * * redmineuser rake -f /path/to/redmine/appdir/Rakefile --silent redmine:email:receive_imap RAILS_ENV="production" host=imap.foo.bar username=redmine@somenet.foo password=xxx
该命令必须在您的 cron 文件中占一行。另请参阅下面的其他示例,这些示例仅显示不带 -f 选项和 cron 部分的 rake 命令。
对于 Windows 服务器,可以使用 pycron 来安排获取任务。
可能需要在机器上打开防火墙,以便出站 TCP 连接到 IMAP 端口 143。
可用的 IMAP 选项
host=HOST IMAP server host (default: 127.0.0.1)
port=PORT IMAP server port (default: 143)
ssl=SSL Use SSL? (default: false)
starttls=STARTTLS Use STARTTLS? (default: false)
username=USERNAME IMAP account
password=PASSWORD IMAP password
folder=FOLDER IMAP folder to read (default: INBOX)
move_on_success=MAILBOX move emails that were successfully received
to MAILBOX instead of deleting them
move_on_failure=MAILBOX move emails that were ignored to MAILBOX
用户和权限选项
unknown_user=ACTION how to handle emails from an unknown user
ACTION can be one of the following values:
ignore: email is ignored (default)
accept: accept as anonymous user
create: create a user account
no_permission_check=1 disable permission checking when receiving
the email
no_account_notice=1 disable new user account notification
default_group=foo,bar adds created user to foo and bar groups
问题属性控制选项
project=PROJECT identifier of the target project
project_from_subaddress=ADDR
select project from subaddress of ADDR found
in To, Cc, Bcc headers
status=STATUS name of the target status
tracker=TRACKER name of the target tracker
category=CATEGORY name of the target category
priority=PRIORITY name of the target priority
assigned_to=ASSIGNEE assignee (username or group name)
fixed_version=VERSION name of the target version
private create new issues as private
allow_override=ATTRS allow email content to set attributes values
ATTRS is a comma separated list of attributes
or 'all' to allow all attributes to be overridable
有关可用于 allow-override 选项的值的列表,请参阅 问题属性。
rake 命令的示例
# No project specified. Emails MUST contain the 'Project' keyword:
rake redmine:email:receive_imap RAILS_ENV="production" \\
host=imap.foo.bar username=redmine@somenet.foo password=xxx
# Fixed project and default tracker specified, but emails can override
# both tracker and priority attributes:
rake redmine:email:receive_imap RAILS_ENV="production" \\
host=imap.foo.bar username=redmine@somenet.foo password=xxx ssl=1 \\
project=foo \\
tracker=bug \\
allow_override=tracker,priority
# Move successful emails to the 'read' mailbox and failed emails to
# the 'failed' mailbox
rake redmine:email:receive_imap RAILS_ENV="production" \\
host=imap.foo.bar username=redmine@somenet.foo password=xxx \\
move_on_success=read move_on_failure=failed
忽略的邮件被标记为“已读”,但不会从 IMAP 服务器中删除--这包括未知用户、未知项目和来自 redmine 发射账户的邮件。
allow_override 选项不仅用于覆盖传递给 rake 的默认值,还用于邮件中的每个属性。如果您想覆盖邮件中的跟踪器,您必须添加 allow_override=tracker 作为参数。
从 POP3 服务器获取邮件¶
可以使用一个 rake 任务(redmine:email:receive_pop3)来从 POP3 服务器获取传入的邮件。
可用的 POP3 选项
host=HOST POP3 server host (default: 127.0.0.1)
port=PORT POP3 server port (default: 110)
username=USERNAME POP3 account
password=PASSWORD POP3 password (use '' if it fails, ex: 'my-password')
apop=1 use APOP authentication (default: false)
delete_unprocessed=1 delete messages that could not be processed
successfully from the server (default
behaviour is to leave them on the server)
有关问题属性控制选项,请参阅上面的 IMAP rake 任务。
从标准输入读取邮件¶
可以使用一个 rake 任务(redmine:email:read)来从标准输入读取单个原始邮件。
有关问题属性控制选项,请参阅上面的 IMAP rake 任务。
示例
# No project specified. Emails MUST contain the 'Project' keyword:
rake redmine:email:read RAILS_ENV="production" < raw_email
# Fixed project and default tracker specified, but emails can override
# both tracker and priority attributes:
rake redmine:email:read RAILS_ENV="production" \\
project=foo \\
tracker=bug \\
allow_override=tracker,priority < raw_email
allow_override 选项不仅用于覆盖传递给 rake 的默认值,还用于邮件中的每个属性。如果您想覆盖邮件中的跟踪器,您必须添加 allow_override=tracker 作为参数。
允许未知用户通过电子邮件创建问题¶
Redmine 具有一个功能,该功能提供了接受未知用户传入电子邮件的能力。为了使用此功能,必须包含一个额外的参数。
unknown_user=ACTION how to handle emails from an unknown user where ACTION can be one of the following values:
ignore: the email is ignored (default)
accept: the sender is considered as an anonymous user and the email is accepted
create: a user account is created for the sender (username/password are sent back to the user) and the email is accepted
权限必须与所选选项一致。例如,如果您选择“创建”,则“非成员”角色必须具有“添加问题”权限,以便未知用户可以通过电子邮件创建问题。如果您选择“接受”,则“匿名”角色必须具有此权限。
如果您通过 rake 任务接收电子邮件,未知用户选项必须写作
unknown_user=[ignore|accept|create]
您可以使用 'no_permission_check' 选项禁用权限检查
no_permission_check=1 disable permission checking when receiving the email
这,连同 'unknown-user' 一起,提供了让任何人向私有项目提交电子邮件的能力。例如
rdm-mailhandler.rb --unknown-user accept --no-permission-check --project=foo
将允许任何人向私有项目 'foo' 提交电子邮件。
TODO:这是真的吗?这与 no_permission_check 选项相关吗?
自Redmine 0.9版本以来,项目不必是公开的,但必须在“管理”->“设置”->“身份验证”选项卡中取消选中身份验证。
如果您不希望由rdm-mailhandler发送给每个新创建用户的“新账户通知电子邮件”,则必须添加选项“--no-account-notice”。该功能从2.3.0版本开始实现,在问题#11498中。以下是一个示例
rdm-mailhandler.rb --unknown-user accept --no-permission-check --project=foo --no-account-notice
使用Rufus Scheduler安排电子邮件接收¶
您可以使用Rufus Scheduler来运行Rake任务检索传入的电子邮件,而不是使用cron来触发Rake任务,这将运行与Redmine相同的进程。
这种方法使用的资源更少,比从cron(或在Windows的任务计划程序中)调用Rake任务要快。
为此,安装rufus-scheduler gem
gem install rufus-scheduler
在/config/initializers/中创建一个what_you_want.rb文件,并将以下内容放入您的文件中。(这里针对POP3账户。根据您的参数和任务进行更改。)
require 'rubygems' require 'rake' require 'rufus-scheduler' load File.join(Rails.root, 'Rakefile') ENV['host']='pop.toto.com' ENV['port']='110' ENV['ssl']='SSL' ENV['username']='redmine@toto.com' ENV['password']='azerty123456' scheduler = Rufus::Scheduler.new # Check emails every 10 mins scheduler.interval '10m' do task = Rake.application['redmine:email:receive_pop3'] task.reenable task.invoke end
重启您的Redmine实例,您的传入电子邮件将按计划检索。
您可以在Rufus-Scheduler中查看调度语法。
工作原理¶
当接收电子邮件时,Redmine使用电子邮件的“发件人”地址来查找相应的用户。来自未知或锁定用户的电子邮件将被忽略。
如果电子邮件主题包含类似“Re: [xxxxxxx #123]”或“[#123]”的内容,则将电子邮件处理为回复,并将备注添加到问题#123。否则,将创建一个新的问题。
请注意,为了创建一个问题,必须提供所有必需的自定义字段。如果没有它们,问题创建将失败。作为替代方案,您可以确保每个自定义字段都有一个默认值,然后在问题创建时使用该值。
目标项目¶
可以使用接收电子邮件时使用的project选项来指定目标项目。这应该是项目的标识符,而不是名称。您可以在URL中轻松找到标识符。
如果您不使用此选项,用户必须在电子邮件正文中指定应添加问题的项目。可以通过在电子邮件正文中插入以下行来完成此操作:"项目:foo"。
示例(电子邮件正文)
This is a new issue that will be added to project foo. Here we have the issue description [...] Project: foo
您可以使用project选项设置默认项目,并允许用户在接收电子邮件时使用allow-override选项覆盖此默认项目。
示例
# Create issues on project foo by default rake redmine:email:receive_imap [...] project=foo allow_override=project
当然,会检查用户权限,如果发送此电子邮件的用户不允许向项目foo添加问题,则此电子邮件将被忽略。
确保目标项目不使用具有无默认值的必需自定义字段,否则问题创建将失败。
从电子邮件子地址获取目标项目¶
该功能是在3.2.0版本(SVN修订r14687)中引入的。可能最好有一个邮箱用于所有传入Redmine实例的电子邮件,而不是每个项目一个。当在redmine@somenet.foo接收电子邮件时,发送到redmine+foo@somenet.foo的电子邮件将导致问题添加到具有标识符foo的项目。
要启用此功能,请将project_from_subaddress=redmine@somenet.foo添加到命令中。
rake redmine:email:receive_imap [...] project_from_subaddress=redmine@somenet.foo
如果项目包含在命令行中,则它将成为默认项目,用于发送给 redmine@somenet.foo 的电子邮件。因此,使用以下命令
rake redmine:email:receive_imap [...] project=bar project_from_subaddress=redmine@somenet.foo
发送给 redmine@somenet.foo 或 redmine+bar@somenet.foo 的电子邮件将在项目 bar 中引发问题;发送给 redmine+foo@somenet.foo 的电子邮件将进入项目 foo。
某些电子邮件服务提供商包括对子地址的支持,如RFC 3598、5233所述。在不支持此功能的情况下,将邮件地址转发到“中央”地址可能会工作(在我的情况下就是这样),即设置一个电子邮件地址,将所有邮件从 redmine+foo@somenet.foo、redmine+bar@somenet.foo 等转发到 redmine@somenet.foo。这很容易管理,并且不需要从具有各自账户凭证的多个账户中检索电子邮件。
问题属性¶
根据您接收电子邮件时使用的选项(参见 allow-override 选项),用户可以在提交问题时覆盖一些属性。
注意:在 Redmine 3.2.0 之前(#20543),一些属性 始终 可覆盖,但这并没有被记录。此行为已更改,所有属性都必须在 allow_override 选项中明确列出才能被覆盖。对于那些希望所有属性都可以覆盖的用户,现在可以使用 allow_override=all(#20543)。
一旦配置了 allow_override,您就可以通过在电子邮件正文中使用适当的密钥词来覆盖这些属性。
示例关键词列表
项目跟踪器状态类别优先级分配给开始日期截止日期目标版本估计工时完成率<自定义字段名称>
可用的值是上下文的值。例如,状态 可用(对于此跟踪器和此项目)是本地化语言中的标签,与用户界面中显示的完全一致或系统默认语言(包括空格,无需引号)。
示例(电子邮件正文)
This is a new issue that overrides a few attributes [...] Project: foo Tracker: Bug Priority: Urgent Status: Resolved
密钥词的格式与 allow-override 选项允许的属性值不同
项目跟踪器状态类别优先级分配给开始日期截止日期fixed_version(即目标版本)估计工时完成率<自定义字段名称>
可以指定多个属性值,以允许仅使用某些密钥词。
示例
# Allow overriding project, tracker, status & priority rake redmine:email:receive_imap [...] allow_override=project,tracker,status,priority
监视者¶
如果发送电子邮件的用户具有“添加问题监视者”的权限,则邮件的“收件人”或“抄送”字段中的用户将自动添加为创建的问题的监视者。
仅在创建问题时添加监视者。在回复中忽略“收件人”或“抄送”字段。请参阅 #7017 和 #8009。
电子邮件格式和附件¶
Redmine试图使用电子邮件的纯文本部分来填充问题的描述。
如果收到仅包含HTML的电子邮件,则从其正文中删除HTML标签。
除非附件的大小超过应用程序设置中定义的 最大附件大小,否则电子邮件附件将自动附加到问题。
截断电子邮件¶
管理员设置可以用来自动截断电子邮件,例如删除论坛回复中的引用消息。为此,在电子邮件通知设置中将发件人邮件标题设置为类似 --以上为回复内容-- 的内容。然后在收件人电子邮件设置中,将相同的行输入到“在这些行之后截断电子邮件”的框中。(也可以允许使用正则表达式进行截断)
另请参阅¶
- 子地址的Mailhandler前端:如何在Redmine <3.2中实现子地址
由Joan Cervan更新大约1年前 · 93次修订