RusRedmineReceivingEmails » History » Version 1

Denis Savitskiy, 2011-07-27 13:50
В процессе..

1 1 Denis Savitskiy
h1. RusRedmineReceivingEmails
2 1 Denis Savitskiy
3 1 Denis Savitskiy
{{>toc}}
4 1 Denis Savitskiy
5 1 Denis Savitskiy
Начиная с версии 0.8.0, Redmine можно настроить на создание и комментирование задач с помощью email.
6 1 Denis Savitskiy
7 1 Denis Savitskiy
h2. Настройка
8 1 Denis Savitskiy
9 1 Denis Savitskiy
You can configure Redmine to receive emails in one of the following ways:
10 1 Denis Savitskiy
11 1 Denis Savitskiy
12 1 Denis Savitskiy
Вы можете настроить Redmine для получения электронной почты одним из следующих способов:
13 1 Denis Savitskiy
14 1 Denis Savitskiy
* Пересылка электронных писем с вашего почтового сервера:
15 1 Denis Savitskiy
16 1 Denis Savitskiy
* Плюсы: работает с удаленнми почтовыми серверами, письма обрабатываются мгновенно, быстро (никакой перезагрузки окружения)
17 1 Denis Savitskiy
* Минусы: требует некоторых настроек агента передачи почты (например: Postfix, Sendmail...)
18 1 Denis Savitskiy
19 1 Denis Savitskiy
* Сбор почты с IMAP или POP3-сервера:
20 1 Denis Savitskiy
21 1 Denis Savitskiy
* Плюсы: простота установки, не нужно сконфигурировать MTA, работает с удаленного почтового сервера
22 1 Denis Savitskiy
* Минусы: письма не обрабатываются мгновенно (должны быть добавлены cron-задания, чтобы получать электронную почту регулярно)
23 1 Denis Savitskiy
24 1 Denis Savitskiy
* Чтение электронных писем из стандартного ввода:
25 1 Denis Savitskiy
26 1 Denis Savitskiy
* Плюсы: удобно для тестирования
27 1 Denis Savitskiy
* Минусы: медленный (перезагрузки окружения каждый раз, когда письмо открывается), нуждается в некоторой конфигурации вашего MTA
28 1 Denis Savitskiy
29 1 Denis Savitskiy
h3. Отправление писем с сервера
30 1 Denis Savitskiy
31 1 Denis Savitskiy
Отдельный скрипт можно использовать для переадресации входящих электронных писем с вашего почтового сервера.
32 1 Denis Savitskiy
Этот скрипт читает необработанные письма со стандартного ввода и направляет их в Redmine через HTTP-запрос.
33 1 Denis Savitskiy
Он находится в вашем redmine каталоге: @extra/mail_handler/rdm-mailhandler.rb@.
34 1 Denis Savitskiy
35 1 Denis Savitskiy
Чтобы использовать его, вам нужно включить API для получение сообщений электронной почты:
36 1 Denis Savitskiy
Зайдите _Настройки_ -> _Приём сообщений_, поставьте флажок на *Включить веб-сервис для входящих сообщений* и введите (или сгенерируйте) API ключ.
37 1 Denis Savitskiy
38 1 Denis Savitskiy
Скопируйте @rdm-mailhandler.rb@ на ваш почтовый сервер и убедитесь, что он исполненяемый, затем настройте ваш MTA.
39 1 Denis Savitskiy
40 1 Denis Savitskiy
Использование:
41 1 Denis Savitskiy
42 1 Denis Savitskiy
<pre>
43 1 Denis Savitskiy
rdm-mailhandler [options] --url=<Redmine URL> --key=<API ключ>
44 1 Denis Savitskiy
45 1 Denis Savitskiy
Обязательные:
46 1 Denis Savitskiy
  -u, --url                      URL сервера Redmine
47 1 Denis Savitskiy
  -k, --key                      Redmine API ключ
48 1 Denis Savitskiy
  
49 1 Denis Savitskiy
Общие:
50 1 Denis Savitskiy
  -h, --help                     помощь
51 1 Denis Savitskiy
  -v, --verbose                  экстра информация
52 1 Denis Savitskiy
  -V, --version                  информация о версии
53 1 Denis Savitskiy
54 1 Denis Savitskiy
Опции управления атрибутами задачи:
55 1 Denis Savitskiy
  -p, --project=PROJECT          идентификатор проекта
56 1 Denis Savitskiy
  -t, --tracker=TRACKER          трекер задачи
57 1 Denis Savitskiy
      --category=CATEGORY        категория задачи
58 1 Denis Savitskiy
      --priority=PRIORITY        приоритет задачи
59 1 Denis Savitskiy
  -o, --allow-override=ATTRS     разрешить содержимому письма переопределять
60 1 Denis Savitskiy
                                 атрибуты, определённые ранее,
61 1 Denis Savitskiy
                                 ATTRS - список атрибутов, разделённых запятой
62 1 Denis Savitskiy
</pre>
63 1 Denis Savitskiy
64 1 Denis Savitskiy
Примеры:
65 1 Denis Savitskiy
66 1 Denis Savitskiy
<pre>
67 1 Denis Savitskiy
  # Нет определённого проекта. Письма ДОЛЖНЫ содержать ключ 'Project':
68 1 Denis Savitskiy
  rdm-mailhandler --url http://redmine.domain.foo --key secret
69 1 Denis Savitskiy
  
70 1 Denis Savitskiy
  # Проект и стандартный трекер определены, но письма могут переопределять 
71 1 Denis Savitskiy
  # оба атрибута:
72 1 Denis Savitskiy
  rdm-mailhandler --url https://domain.foo/redmine --key secret \\
73 1 Denis Savitskiy
                  --project foo \\
74 1 Denis Savitskiy
                  --tracker bug \\
75 1 Denis Savitskiy
                  --allow-override tracker,priority
76 1 Denis Savitskiy
</pre>
77 1 Denis Savitskiy
78 1 Denis Savitskiy
Here is an example for a Postfix local alias (which is usually specified in @/etc/aliases@):
79 1 Denis Savitskiy
80 1 Denis Savitskiy
<pre>
81 1 Denis Savitskiy
foo: "|/path/to/rdm-mailhandler.rb --url http://redmine.domain --key secret --project foo"
82 1 Denis Savitskiy
</pre>
83 1 Denis Savitskiy
84 1 Denis Savitskiy
If your domain is setup as a virtual mailbox map (so that you use /etc/postfix/virtual_mailbox_maps to do mappings in the form @ user@example.com /path/example.com/user@) you should:
85 1 Denis Savitskiy
86 1 Denis Savitskiy
* create a mapping in @/etc/virtual@ like: @ foo@example.org foo@
87 1 Denis Savitskiy
* modify @/etc/postfix/main.cf@ to specify a transport file: @transport_maps = hash:/etc/postfix/transport@
88 1 Denis Savitskiy
* within the transport file add a line like: @ foo@example.org local:@
89 1 Denis Savitskiy
90 1 Denis Savitskiy
*Explanation:* - When you define virtual_mailbox_maps for a domain the default transport is virtual, which means specifying a local alias in @/etc/postfix/virtual@ will fail (with "unknown user"). To fix this, we override the default transport by specifying a local transport for the email address in question, which means the local alias will resolve correctly, and your script will be executed.
91 1 Denis Savitskiy
92 1 Denis Savitskiy
A front-end to rdm-mailhandler.rb has been written to allow specifying projects trough sub-addresses (name+project@example.com). See [[MailhandlerSubAddress]]
93 1 Denis Savitskiy
94 1 Denis Savitskiy
h3. Fetching emails from an IMAP server
95 1 Denis Savitskiy
96 1 Denis Savitskiy
A rake task (@redmine:email:receive_imap@) can be used to fetch incoming emails from an IMAP server. When you run the rake command from a cron job you can include the switch @-f /path/to/redmine/appdir/Rakefile@ on the rake command, because otherwise the rakefile is not found. This is an example line for a cron file that fetches mails every 30 minutes:
97 1 Denis Savitskiy
98 1 Denis Savitskiy
<code>
99 1 Denis Savitskiy
*/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 
100 1 Denis Savitskiy
</code>
101 1 Denis Savitskiy
102 1 Denis Savitskiy
If your setup is working, but you receive mails from the cron daemon, you can suppress the output from the rake command by adding the --silent switch. That should stop cron sending mails on every execution of the command.
103 1 Denis Savitskiy
104 1 Denis Savitskiy
<code>
105 1 Denis Savitskiy
*/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 
106 1 Denis Savitskiy
</code>
107 1 Denis Savitskiy
108 1 Denis Savitskiy
The command has to go on a single line in your cronfile. Also see the other examples below, which only show the rake commands without the @-f@ option and without the cron part. 
109 1 Denis Savitskiy
110 1 Denis Savitskiy
For Windows as server "pycron":http://www.kalab.com/freeware/pycron/pycron.htm can be used to schedule a fetch task.
111 1 Denis Savitskiy
112 1 Denis Savitskiy
It can be necessary that you open the firewall on the machine for outgoing TCP connections to IMAP port 143.
113 1 Denis Savitskiy
114 1 Denis Savitskiy
Available IMAP options:
115 1 Denis Savitskiy
<pre>
116 1 Denis Savitskiy
  host=HOST                IMAP server host (default: 127.0.0.1)
117 1 Denis Savitskiy
  port=PORT                IMAP server port (default: 143)
118 1 Denis Savitskiy
  ssl=SSL                  Use SSL? (default: false)
119 1 Denis Savitskiy
  username=USERNAME        IMAP account
120 1 Denis Savitskiy
  password=PASSWORD        IMAP password
121 1 Denis Savitskiy
  folder=FOLDER            IMAP folder to read (default: INBOX)
122 1 Denis Savitskiy
  move_on_success=MAILBOX  move emails that were successfully received
123 1 Denis Savitskiy
                           to MAILBOX instead of deleting them
124 1 Denis Savitskiy
  move_on_failure=MAILBOX  move emails that were ignored to MAILBOX
125 1 Denis Savitskiy
</pre>
126 1 Denis Savitskiy
127 1 Denis Savitskiy
Issue attributes control options:
128 1 Denis Savitskiy
<pre>
129 1 Denis Savitskiy
  project=PROJECT          identifier of the target project
130 1 Denis Savitskiy
  tracker=TRACKER          name of the target tracker
131 1 Denis Savitskiy
  category=CATEGORY        name of the target category
132 1 Denis Savitskiy
  priority=PRIORITY        name of the target priority
133 1 Denis Savitskiy
  allow_override=ATTRS     allow email content to override attributes
134 1 Denis Savitskiy
                           specified by previous options
135 1 Denis Savitskiy
                           ATTRS is a comma separated list of attributes
136 1 Denis Savitskiy
</pre>
137 1 Denis Savitskiy
138 1 Denis Savitskiy
Примеры для rake команды:
139 1 Denis Savitskiy
140 1 Denis Savitskiy
<pre>
141 1 Denis Savitskiy
  # No project specified. Emails MUST contain the 'Project' keyword:
142 1 Denis Savitskiy
  
143 1 Denis Savitskiy
  rake redmine:email:receive_imap RAILS_ENV="production" \\
144 1 Denis Savitskiy
    host=imap.foo.bar username=redmine@somenet.foo password=xxx
145 1 Denis Savitskiy
146 1 Denis Savitskiy
147 1 Denis Savitskiy
  # Fixed project and default tracker specified, but emails can override
148 1 Denis Savitskiy
  # both tracker and priority attributes:
149 1 Denis Savitskiy
  
150 1 Denis Savitskiy
  rake redmine:email:receive_imap RAILS_ENV="production" \\
151 1 Denis Savitskiy
    host=imap.foo.bar username=redmine@somenet.foo password=xxx ssl=1 \\
152 1 Denis Savitskiy
    project=foo \\
153 1 Denis Savitskiy
    tracker=bug \\
154 1 Denis Savitskiy
    allow_override=tracker,priority
155 1 Denis Savitskiy
156 1 Denis Savitskiy
  # Move successful emails to the 'read' mailbox and failed emails to
157 1 Denis Savitskiy
  # the 'failed' mailbox
158 1 Denis Savitskiy
  
159 1 Denis Savitskiy
  rake redmine:email:receive_imap RAILS_ENV="production" \\
160 1 Denis Savitskiy
    host=imap.foo.bar username=redmine@somenet.foo password=xxx \\
161 1 Denis Savitskiy
    move_on_success=read move_on_failure=failed
162 1 Denis Savitskiy
163 1 Denis Savitskiy
</pre>
164 1 Denis Savitskiy
165 1 Denis Savitskiy
166 1 Denis Savitskiy
Ignored emails are marked as 'Seen' but are not deleted from the IMAP server--these include unknown user, unknown project and emails from the redmine emission account.
167 1 Denis Savitskiy
168 1 Denis Savitskiy
The option _allow_override_ is not only for overriding default values given to rake, but for every attribute in a mail. If you want to override the tracker in your mail you have to add _allow_override=tracker_ as parameter.
169 1 Denis Savitskiy
170 1 Denis Savitskiy
h3. Fetching emails from a POP3 server
171 1 Denis Savitskiy
172 1 Denis Savitskiy
_Only available in trunk and future 1.0._
173 1 Denis Savitskiy
174 1 Denis Savitskiy
A rake task (@redmine:email:receive_pop3@) can be used to fetch incoming emails from a POP3 server.
175 1 Denis Savitskiy
176 1 Denis Savitskiy
Доступные опции POP3:
177 1 Denis Savitskiy
<pre>
178 1 Denis Savitskiy
  host=HOST                POP3 server host (default: 127.0.0.1)
179 1 Denis Savitskiy
  port=PORT                POP3 server port (default: 110)
180 1 Denis Savitskiy
  username=USERNAME        POP3 account
181 1 Denis Savitskiy
  password=PASSWORD        POP3 password
182 1 Denis Savitskiy
  apop=1                   use APOP authentication (default: false)
183 1 Denis Savitskiy
  delete_unprocessed=1     delete messages that could not be processed
184 1 Denis Savitskiy
                           successfully from the server (default
185 1 Denis Savitskiy
                           behaviour is to leave them on the server)
186 1 Denis Savitskiy
</pre>
187 1 Denis Savitskiy
188 1 Denis Savitskiy
See the IMAP rake task above for issue attributes control options.
189 1 Denis Savitskiy
190 1 Denis Savitskiy
h3. Чтение писем со стандартного ввода
191 1 Denis Savitskiy
192 1 Denis Savitskiy
A rake task (@redmine:email:receive@) can be used to read a single raw email from the standard input.
193 1 Denis Savitskiy
194 1 Denis Savitskiy
<pre>
195 1 Denis Savitskiy
Issue attributes control options:
196 1 Denis Savitskiy
  project=PROJECT          identifier of the target project
197 1 Denis Savitskiy
  tracker=TRACKER          name of the target tracker
198 1 Denis Savitskiy
  category=CATEGORY        name of the target category
199 1 Denis Savitskiy
  priority=PRIORITY        name of the target priority
200 1 Denis Savitskiy
  allow_override=ATTRS     allow email content to override attributes
201 1 Denis Savitskiy
                           specified by previous options
202 1 Denis Savitskiy
                           ATTRS is a comma separated list of attributes
203 1 Denis Savitskiy
</pre>
204 1 Denis Savitskiy
205 1 Denis Savitskiy
Примеры:
206 1 Denis Savitskiy
207 1 Denis Savitskiy
<pre>
208 1 Denis Savitskiy
  # No project specified. Emails MUST contain the 'Project' keyword:
209 1 Denis Savitskiy
  rake redmine:email:read RAILS_ENV="production" < raw_email
210 1 Denis Savitskiy
211 1 Denis Savitskiy
  # Fixed project and default tracker specified, but emails can override
212 1 Denis Savitskiy
  # both tracker and priority attributes:
213 1 Denis Savitskiy
  rake redmine:email:read RAILS_ENV="production" \\
214 1 Denis Savitskiy
                  project=foo \\
215 1 Denis Savitskiy
                  tracker=bug \\
216 1 Denis Savitskiy
                  allow_override=tracker,priority < raw_email
217 1 Denis Savitskiy
</pre>
218 1 Denis Savitskiy
219 1 Denis Savitskiy
The option _allow_override_ is not only for overriding default values given to rake, but for every attribute in a mail. If you want to override the tracker in your mail you have to add _allow_override=tracker_ as parameter.
220 1 Denis Savitskiy
221 1 Denis Savitskiy
h3. Разрешение анонимным пользоваателям создавать задачи с помощью email
222 1 Denis Savitskiy
223 1 Denis Savitskiy
In order to enable this option, extra parameters have to be included.
224 1 Denis Savitskiy
225 1 Denis Savitskiy
<pre>
226 1 Denis Savitskiy
unknown_user=ACTION     how to handle emails from an unknown user ACTION can be one of the following values:
227 1 Denis Savitskiy
                        ignore: email is ignored (default)
228 1 Denis Savitskiy
                        accept: accept as anonymous user
229 1 Denis Savitskiy
                        create: create a user account
230 1 Denis Savitskiy
231 1 Denis Savitskiy
no_permission_check=1   disable permission checking when receiving the email
232 1 Denis Savitskiy
</pre>
233 1 Denis Savitskiy
234 1 Denis Savitskiy
Since version 0.9 project doesn't have to be public, but authentication required in Administration-> Settings->Authentication tab has to be unchecked.
235 1 Denis Savitskiy
236 1 Denis Savitskiy
h2. Как это работает
237 1 Denis Savitskiy
238 1 Denis Savitskiy
When receiving an email, Redmine uses the From address of the email to find the corresponding user. Emails received from unknown or locked users are ignored.
239 1 Denis Savitskiy
240 1 Denis Savitskiy
If the email subject contains something like "Re: *[xxxxxxx !#123]*", the email is processed as a reply and a note is added to issue !#123. Otherwise, a new issue is created.
241 1 Denis Savitskiy
242 1 Denis Savitskiy
h3. Target project
243 1 Denis Savitskiy
244 1 Denis Savitskiy
The target project can be specified using the @project@ option when receiving emails.  This should be the identifier of the project and *not* the name.  You can easily find the identifier in the url.
245 1 Denis Savitskiy
246 1 Denis Savitskiy
If you don't use this option, users have to specify in the email body which project the issue should be added to. This can be done by inserting a line in the email body like this: @"Project: foo"@.
247 1 Denis Savitskiy
248 1 Denis Savitskiy
Пример (тело письма):
249 1 Denis Savitskiy
250 1 Denis Savitskiy
<pre>
251 1 Denis Savitskiy
This is a new issue that will be added to project foo.
252 1 Denis Savitskiy
Here we have the issue description
253 1 Denis Savitskiy
[...]
254 1 Denis Savitskiy
255 1 Denis Savitskiy
Project: foo
256 1 Denis Savitskiy
</pre>
257 1 Denis Savitskiy
258 1 Denis Savitskiy
You can set a default project using the @project@ option and let users override this default project by using the @allow-override@ option when receiving emails.
259 1 Denis Savitskiy
Example:
260 1 Denis Savitskiy
261 1 Denis Savitskiy
<pre>
262 1 Denis Savitskiy
  # Create issues on project foo by default
263 1 Denis Savitskiy
  rake redmine:email:receive_imap [...] project=foo allow_override=project
264 1 Denis Savitskiy
</pre>
265 1 Denis Savitskiy
266 1 Denis Savitskiy
Of course, user permissions are checked and this email would be ignored if the user who sent this email is not allowed to add issues to project foo.
267 1 Denis Savitskiy
Make sure that the target project doesn't use *required* custom fields with no default value for its issues, otherwise the creation of the issue will fail.
268 1 Denis Savitskiy
269 1 Denis Savitskiy
h3. Параметры задачи
270 1 Denis Savitskiy
271 1 Denis Savitskiy
Based on the options you use when receiving emails (see @allow-override@ option), users may be able to override some attributes when submitting an issue.
272 1 Denis Savitskiy
This can be done by using the following keywords in the email body (just like @Project@): @Tracker@, @Category@, @Priority@, @Status@.
273 1 Denis Savitskiy
274 1 Denis Savitskiy
Пример (тело письма):
275 1 Denis Savitskiy
276 1 Denis Savitskiy
<pre>
277 1 Denis Savitskiy
This is a new issue that overrides a few attributes
278 1 Denis Savitskiy
[...]
279 1 Denis Savitskiy
280 1 Denis Savitskiy
Project: foo
281 1 Denis Savitskiy
Tracker: Bug
282 1 Denis Savitskiy
Priority: Urgent
283 1 Denis Savitskiy
Status: Resolved
284 1 Denis Savitskiy
</pre>
285 1 Denis Savitskiy
286 1 Denis Savitskiy
h3. Наблюдатели
287 1 Denis Savitskiy
288 1 Denis Savitskiy
If the user who sends the email has the 'Add issue watchers' permission, users that are in To or Cc field of the email are automatically added as watchers of the created issue.
289 1 Denis Savitskiy
290 1 Denis Savitskiy
h3. Формат письма и вложения
291 1 Denis Savitskiy
292 1 Denis Savitskiy
Redmine tries to use the plain text part of the email to fill the description of the issue.
293 1 Denis Savitskiy
If a HTML-only email is received, HTML tags are removed from its body.
294 1 Denis Savitskiy
295 1 Denis Savitskiy
Email attachments are automatically attached to the issue, unless their size exceeds the [[RedmineSettings#Attachment-max-size|maximum attachment size]] defined in the application settings.