debian-mirror-gitlab/doc/development/emails.md

142 lines
5.5 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2021-04-17 20:07:23 +05:30
# Working with email in development
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
## Ensuring compatibility with mailer Sidekiq jobs
A Sidekiq job is enqueued whenever `deliver_later` is called on an `ActionMailer`.
If a mailer argument needs to be added or removed, it is important to ensure
both backward and forward compatibility. Adhere to the Sidekiq Style Guide steps for
[changing the arguments for a worker](sidekiq_style_guide.md#changing-the-arguments-for-a-worker).
In the following example from [`NotificationService`](https://gitlab.com/gitlab-org/gitlab/-/blob/33ccb22e4fc271dbaac94b003a7a1a2915a13441/app/services/notification_service.rb#L74)
adding or removing an argument in this mailer's definition may cause problems
during deployment before all Rails and Sidekiq nodes have the updated code.
```ruby
mailer.unknown_sign_in_email(user, ip, time).deliver_later
```
2018-03-17 18:26:18 +05:30
## Sent emails
To view rendered emails "sent" in your development instance, visit
[`/rails/letter_opener`](http://localhost:3000/rails/letter_opener).
2019-12-04 20:38:33 +05:30
Please note that [S/MIME signed](../administration/smime_signing_email.md) emails
[cannot be currently previewed](https://github.com/fgrehm/letter_opener_web/issues/96) with
`letter_opener`.
2018-03-17 18:26:18 +05:30
## Mailer previews
Rails provides a way to preview our mailer templates in HTML and plaintext using
2021-01-03 14:25:43 +05:30
sample data.
2018-03-17 18:26:18 +05:30
2020-05-24 23:13:21 +05:30
The previews live in [`app/mailers/previews`](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/app/mailers/previews) and can be viewed at
2018-03-17 18:26:18 +05:30
[`/rails/mailers`](http://localhost:3000/rails/mailers).
2020-04-22 19:07:51 +05:30
See the [Rails guides](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails) for more information.
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
## Incoming email
1. Go to the GitLab installation directory.
1. Find the `incoming_email` section in `config/gitlab.yml`, enable the
feature and fill in the details for your specific IMAP server and email
account:
2019-09-30 21:07:59 +05:30
Configuration for Gmail / Google Apps, assumes mailbox `gitlab-incoming@gmail.com`:
```yaml
incoming_email:
enabled: true
2021-04-17 20:07:23 +05:30
# The email address including the %{key} placeholder that will be replaced to reference the item being replied to. This %{key} should be included in its entirety within the email address and not replaced by another value.
# For example: emailadress+%key@gmail.com.
2019-09-30 21:07:59 +05:30
# The placeholder can be omitted but if present, it must appear in the "user" part of the address (before the `@`).
address: "gitlab-incoming+%{key}@gmail.com"
# Email account username
# With third party providers, this is usually the full email address.
# With self-hosted email servers, this is usually the user part of the email address.
user: "gitlab-incoming@gmail.com"
# Email account password
password: "[REDACTED]"
# IMAP server host
host: "imap.gmail.com"
# IMAP server port
port: 993
# Whether the IMAP server uses SSL
ssl: true
# Whether the IMAP server uses StartTLS
start_tls: false
# The mailbox where incoming mail will end up. Usually "inbox".
mailbox: "inbox"
# The IDLE command timeout.
idle_timeout: 60
2020-05-24 23:13:21 +05:30
# Whether to expunge (permanently remove) messages from the mailbox when they are deleted after delivery
expunge_deleted: false
2019-09-30 21:07:59 +05:30
```
2021-02-22 17:27:13 +05:30
As mentioned, the part after `+` is ignored, and this message is sent to the mailbox for `gitlab-incoming@gmail.com`.
2018-03-27 19:54:05 +05:30
2018-05-09 12:01:36 +05:30
1. Run this command in the GitLab root directory to launch `mail_room`:
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
bundle exec mail_room -q -c config/mail_room.yml
```
2018-03-27 19:54:05 +05:30
1. Verify that everything is configured correctly:
2020-03-13 15:44:24 +05:30
```shell
2019-09-30 21:07:59 +05:30
bundle exec rake gitlab:incoming_email:check RAILS_ENV=development
```
2018-03-27 19:54:05 +05:30
1. Reply by email should now be working.
2018-10-15 14:42:47 +05:30
## Email namespace
2020-03-13 15:44:24 +05:30
As of GitLab 11.7, we support a new format for email handler addresses. This was done to
2019-02-15 15:39:39 +05:30
support catch-all mailboxes.
2018-10-15 14:42:47 +05:30
2019-02-15 15:39:39 +05:30
If you need to implement a feature which requires a new email handler, follow these rules
for the format of the email key:
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
- Actions are always at the end, separated by `-`. For example `-issue` or `-merge-request`
2019-02-15 15:39:39 +05:30
- If your feature is related to a project, the key begins with the project identifiers (project path slug
2020-05-24 23:13:21 +05:30
and project ID), separated by `-`. For example, `gitlab-org-gitlab-foss-20`
2019-02-15 15:39:39 +05:30
- Additional information, such as an author's token, can be added between the project identifiers and
2020-03-13 15:44:24 +05:30
the action, separated by `-`. For example, `gitlab-org-gitlab-foss-20-Author_Token12345678-issue`
2019-02-15 15:39:39 +05:30
- You register your handlers in `lib/gitlab/email/handler.rb`
Examples of valid email keys:
2019-12-21 20:55:43 +05:30
- `gitlab-org-gitlab-foss-20-Author_Token12345678-issue` (create a new issue)
- `gitlab-org-gitlab-foss-20-Author_Token12345678-merge-request` (create a new merge request)
2019-09-30 21:07:59 +05:30
- `1234567890abcdef1234567890abcdef-unsubscribe` (unsubscribe from a conversation)
- `1234567890abcdef1234567890abcdef` (reply to a conversation)
2019-02-15 15:39:39 +05:30
2020-07-28 23:09:34 +05:30
Please note that the action `-issue-` is used in GitLab as the handler for the Service Desk feature.
2019-02-15 15:39:39 +05:30
### Legacy format
Although we continue to support the older legacy format, no new features should use a legacy format.
These are the only valid legacy formats for an email handler:
2018-10-15 14:42:47 +05:30
2019-09-30 21:07:59 +05:30
- `path/to/project+namespace`
- `path/to/project+namespace+action`
- `namespace`
- `namespace+action`
2018-10-15 14:42:47 +05:30
2020-07-28 23:09:34 +05:30
Please note that `path/to/project` is used in GitLab as the handler for the Service Desk feature.
2018-10-15 14:42:47 +05:30
2018-03-17 18:26:18 +05:30
---
[Return to Development documentation](README.md)