32

By default gitlab has the next configuration in gitlab.yml :

email:
  from: notify@gitlabhq.com
  host: gitlabhq.com

but, I need to specify other variables (host, port, user, password, etc) to use another mail server.

How I do that?

el_quick
  • 4,656
  • 11
  • 45
  • 53
  • I am looking for the same solution. Please let me know if you have found any better way – Hardik Joshi Jun 23 '12 at 14:02
  • It is not possible for you to install a simple smtp relay on the host running gitlab ? You will then be able to configure it to relay mails using your authenticated mail server – Cedric Gatay Jun 24 '12 at 10:18
  • Look at here: http://stackoverflow.com/questions/16201090/gitlab-email-notifications-not-sending/16690884#16690884 ------ – Girish KG May 22 '13 at 13:23

7 Answers7

40

Now it is totally different in Gitlab 5.2+.

It is in "/home/git/gitlab/config/initializers/smtp_settings.rb.sample" and we just need to follow the instructions in that.

Community
  • 1
  • 1
Girish KG
  • 1,074
  • 11
  • 4
30

Note: This method was useful for older versions of Gitlab. See the answer of Girish for newer versions.


At the end of config/environments/production.rb you can add something like this:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address => 'yourserver.com',
      :port => 25,
      :domain => 'gitlab.yourserver.com',
      :authentication => :plain,
      :user_name => 'gitlab@yourserver.com',
      :password => 'yourPassword',
      :enable_starttls_auto => true
  }

Refer to the ActionMailer documentation for a more detailed description of possible configurations: http://api.rubyonrails.org/classes/ActionMailer/Base.html

Note: You may have to edit the file again after a Gitlab update

Community
  • 1
  • 1
Adrian
  • 2,233
  • 1
  • 22
  • 33
  • 4
    note: `:authentication => :login` or `:cram_md5` may be what's needed, also `:enable_starttls_auto => false` should be used when tls/ssl isn't being used on your mail server (typically when the port is 25 as above.) – ocodo Mar 30 '13 at 11:40
  • 1
    Good answer. This works but it is a cleaner option the suggested one by Girish KG. If you modify the production.rb file, you can find problems upgrading gitlab by git and you will need to handle some repository conflicts before get the upgrade succesfully. – ProtheanTom Dec 26 '13 at 16:29
10

This confused me too. But to change the mail setting you edit them in config/environments/production.rb Just add a config.action_mailer.smtp_settings like a regular rails app.

Joshua
  • 2,079
  • 20
  • 29
7

For Gitlab > 7 omnibus, edit /etc/gitlab/gitlab.rb as below and run sudo gitlab-ctl reconfigure

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'none'

Source: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md

topher
  • 14,790
  • 7
  • 54
  • 70
5

The email:host: configuration in gitlab.yml isn't actually for the mail server/SMTP host. It's used to construct the links to your Gitlab host in the email. We call our gitlab server 'gitlab.local' (and have a DNS entry for it), so our configuration says host: gitlab.local.

This way, when users receive an email from Gitlab, the links will work, instead of linking to http://localhost/, as is the default.

There's some redundant configuration in there. For the git clone URLs to be displayed correctly within Gitlab, you also need to configure web:host: and git_host:host: with the same host name.

web:
  host: gitlab.local
  port: 80
  https: false

email:
   host: gitlab.local
   protocol: http

git_host:
   host: gitlab.local

If you are using HTTPS, change web:https:, web:port:, and email:protocol:.

Jimothy
  • 9,150
  • 5
  • 30
  • 33
  • I found this answer useful for my own scenario of setting up proper links in GitLab account invitation emails sent from my GitLab local VM; see a question/answer I posted here: http://stackoverflow.com/questions/24589361/how-to-change-the-host-ip-sent-in-emails-to-new-gitlab-users-to-a-publicly-visib – Dan Nissenbaum Jul 06 '14 at 16:00
3

This is my entries at the end in /config/environment/production.rb and that is working for me.


Comment out sendmail options and use external SMTP relays


  # #config.action_mailer.delivery_method = :sendmail ## Comment out this

  # Defaults to:

  # # config.action_mailer.sendmail_settings = {

  # #   :location => '/usr/sbin/sendmail',

  # #   :arguments => '-i -t'

  # # }

  config.action_mailer.perform_deliveries = true

  config.action_mailer.raise_delivery_errors = true

  # # SMTP Settings

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {

      :address => '10.146.10.90', ## My SMTP Relay/Gateway

      :port => 25, ## SMTP Port

      :domain => 'gitlab.example.com', ## My Domain

      :authentication => :plain, ## Let it be plain as it is inside my LAN

      ##:user_name => 'gitlab@yourserver.com', ## This is not required as long as 

      ##:password => 'yourPassword', ## SMTP Gateway allows anonymous relay

      ##:enable_starttls_auto => true ## In LAN

      ##:user_name => '',

      ##:password => '',

      :enable_starttls_auto => true
  }
end

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Girish KG
  • 1,074
  • 11
  • 4
  • 1
    People who downwote, please add a comment saying why they downvoted. So that other people can understand why this author's method won't work / is not the best. Please. – Aswin Kumar Mar 09 '14 at 19:51
  • Is it possible to accomplish this all through the /etc/gitlab/gitlab.rb file? – unc0nnected Nov 05 '14 at 21:50
0

Apparently the location of these settings has changed (a few times) since this question was originally asked. Currently as of 2018-11-02:

The settings are in gitlab.rb as per the official documentation:

enter image description here

https://docs.gitlab.com/omnibus/settings/smtp.html