1--- 2stage: none 3group: unassigned 4info: 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 5--- 6 7# Working with email in development 8 9## Ensuring compatibility with mailer Sidekiq jobs 10 11A Sidekiq job is enqueued whenever `deliver_later` is called on an `ActionMailer`. 12If a mailer argument needs to be added or removed, it is important to ensure 13both backward and forward compatibility. Adhere to the Sidekiq Style Guide steps for 14[changing the arguments for a worker](sidekiq_style_guide.md#changing-the-arguments-for-a-worker). 15 16In the following example from [`NotificationService`](https://gitlab.com/gitlab-org/gitlab/-/blob/33ccb22e4fc271dbaac94b003a7a1a2915a13441/app/services/notification_service.rb#L74) 17adding or removing an argument in this mailer's definition may cause problems 18during deployment before all Rails and Sidekiq nodes have the updated code. 19 20```ruby 21mailer.unknown_sign_in_email(user, ip, time).deliver_later 22``` 23 24## Sent emails 25 26To view rendered emails "sent" in your development instance, visit 27[`/rails/letter_opener`](http://localhost:3000/rails/letter_opener). 28 29[S/MIME signed](../administration/smime_signing_email.md) emails 30[cannot be currently previewed](https://github.com/fgrehm/letter_opener_web/issues/96) with 31`letter_opener`. 32 33## Mailer previews 34 35Rails provides a way to preview our mailer templates in HTML and plaintext using 36sample data. 37 38The previews live in [`app/mailers/previews`](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/app/mailers/previews) and can be viewed at 39[`/rails/mailers`](http://localhost:3000/rails/mailers). 40 41See the [Rails guides](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails) for more information. 42 43## Incoming email 44 451. Go to the GitLab installation directory. 46 471. Find the `incoming_email` section in `config/gitlab.yml`, enable the 48 feature and fill in the details for your specific IMAP server and email 49 account: 50 51 Configuration for Gmail / Google Apps, assumes mailbox `gitlab-incoming@gmail.com`: 52 53 ```yaml 54 incoming_email: 55 enabled: true 56 57 # The email address including the %{key} placeholder that will be replaced to reference the 58 # item being replied to. This %{key} should be included in its entirety within the email 59 # address and not replaced by another value. 60 # For example: emailadress+%{key}@gmail.com. 61 # The placeholder must appear in the "user" part of the address (before the `@`). It can be omitted but some features, 62 # including Service Desk, may not work properly. 63 address: "gitlab-incoming+%{key}@gmail.com" 64 65 # Email account username 66 # With third party providers, this is usually the full email address. 67 # With self-hosted email servers, this is usually the user part of the email address. 68 user: "gitlab-incoming@gmail.com" 69 # Email account password 70 password: "[REDACTED]" 71 72 # IMAP server host 73 host: "imap.gmail.com" 74 # IMAP server port 75 port: 993 76 # Whether the IMAP server uses SSL 77 ssl: true 78 # Whether the IMAP server uses StartTLS 79 start_tls: false 80 81 # The mailbox where incoming mail will end up. Usually "inbox". 82 mailbox: "inbox" 83 # The IDLE command timeout. 84 idle_timeout: 60 85 86 # Whether to expunge (permanently remove) messages from the mailbox when they are deleted after delivery 87 expunge_deleted: false 88 ``` 89 90 As mentioned, the part after `+` is ignored, and this message is sent to the mailbox for `gitlab-incoming@gmail.com`. 91 921. Run this command in the GitLab root directory to launch `mail_room`: 93 94 ```shell 95 bundle exec mail_room -q -c config/mail_room.yml 96 ``` 97 981. Verify that everything is configured correctly: 99 100 ```shell 101 bundle exec rake gitlab:incoming_email:check RAILS_ENV=development 102 ``` 103 1041. Reply by email should now be working. 105 106## Email namespace 107 108As of GitLab 11.7, we support a new format for email handler addresses. This was done to 109support catch-all mailboxes. 110 111If you need to implement a feature which requires a new email handler, follow these rules 112for the format of the email key: 113 114- Actions are always at the end, separated by `-`. For example `-issue` or `-merge-request` 115- If your feature is related to a project, the key begins with the project identifiers (project path slug 116 and project ID), separated by `-`. For example, `gitlab-org-gitlab-foss-20` 117- Additional information, such as an author's token, can be added between the project identifiers and 118 the action, separated by `-`. For example, `gitlab-org-gitlab-foss-20-Author_Token12345678-issue` 119- You register your handlers in `lib/gitlab/email/handler.rb` 120 121Examples of valid email keys: 122 123- `gitlab-org-gitlab-foss-20-Author_Token12345678-issue` (create a new issue) 124- `gitlab-org-gitlab-foss-20-Author_Token12345678-merge-request` (create a new merge request) 125- `1234567890abcdef1234567890abcdef-unsubscribe` (unsubscribe from a conversation) 126- `1234567890abcdef1234567890abcdef` (reply to a conversation) 127 128The action `-issue-` is used in GitLab as the handler for the Service Desk feature. 129 130### Legacy format 131 132Although we continue to support the older legacy format, no new features should use a legacy format. 133These are the only valid legacy formats for an email handler: 134 135- `path/to/project+namespace` 136- `path/to/project+namespace+action` 137- `namespace` 138- `namespace+action` 139 140In GitLab, the handler for the Service Desk feature is `path/to/project`. 141 142--- 143 144[Return to Development documentation](index.md) 145