Using Gmail to send email

I’ve recently set up a Gitlab server on my own hardware, and I’m trying to get an account up and running. I do not have a working email server on this hardware and as such I’m trying to get the confirmation email to be sent using a Gmail account I’ve set up explicitly for this purpose. I’ve edited my gitlab.rb file file to include Gmail’s settings, but I still can’t get things to work. Any ideas?

gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "<username>@gmail.com"
gitlab_rails['smtp_password'] = "<password>"
gitlab_rails['smtp_domain'] = "gmail.com"
gitlab_rails['smtp_authentication'] = :plain
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

For starters see the example in the documentation https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md#example-configuration

I see that you have set authentication to :plain, whereas this should be a string according to docs. Try the settings above and report back.

In my stupidity, I forgot about the admin account. Now, I can create a user through there with no issue, which was why I opened up this topic in the first place. But, my problem still remains about sending out emails: it doesn’t work. I’ve updated my configurations with those sample configs although I’m still having issues, even after having Gitlab resend the confirmation email. Is there anything else I should try?

EDIT: Here’s something from the sidekiq.log file that could prove useful:

2015-05-03_19:15:42.35591 2015-05-03T19:15:42.355Z 5295 TID-7dajg WARN: 
{"retry"=>true, "queue"=>"mailer", 
"class"=>"Devise::Async::Backend::Sidekiq", 
"args"=>["confirmation_instructions", "User", "2", 
"SkXcS1j3HnxzQYPE_pzZ", {}], "jid"=>"4ad2e3c7ae24e568598be054", 
"enqueued_at"=>1430679573.460593, "error_message"=>"SSL_connect 
returned=1 errno=0 state=SSLv3 read server certificate B: certificate 
verify failed", "error_class"=>"OpenSSL::SSL::SSLError", 
"failed_at"=>1430679574.3812318, "retry_count"=>5, 
"retried_at"=>1430680542.3493233}

From the top of my mind:

  1. Check your firewall
  2. If you installed postfix check the queue with postqueue -p
  3. See /var/log/mail.log for any bounces
  4. See whether sidekiq has any error with gitlab-ctl tail sidekiq (gitlab-ctl tail for all logs)

Send a test mail from your server

echo test | mail -s test username@gmail.com

Ok nice now we’re getting somewhere. Check this issue https://gitlab.com/gitlab-org/gitlab-ce/issues/1558

I’ve taken the steps listed in both of your posts, but the echo test | mail -s test username@gmail.com command does nothing. What firewall settings do I have to check, exactly? I’ve allowed port 25 and port 587, but I get some error in the log:

May  3 17:36:58 netbook-server postfix/smtp[19210]: 60424321061: to=<xxxx@gmail.com>, relay=smtp.gmail.com[74.125.29.109]:587, delay=326414, delays=326413/0.25/0.24/0.03, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.29.109] said: 530 5.7.0 Must issue a STARTTLS command first. m195sm23534424qhb.35 - gsmtp (in reply to MAIL FROM command))

At this point, since I’ve set up my user account, I guess this error is not crucial to be fixed, but it’d be nice to know everything is working.

Can you try the fix proposed in https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests/342 ?

gitlab-rails['smtp_ca_file'] = '/opt/gitlab/embedded/ssl/certs/cacert.pem'

It lives! Now I get email from the Gmail account I set up. Thanks! The fix was I think a combination of your suggested fix but also enabling access for less secure apps at this URL. I hope this fixes the issue for other people!

1 Like

I’ve followed all the instruction from this post but I can’t send confirmation email through gmail account: my sidekiq log reports:

2016-01-14_09:08:26.37706 2016-01-14T09:08:26.376Z 26570 TID-z08uw ActionMailer::DeliveryJob JID-0627de829621f083381e610c INFO: start
2016-01-14_09:09:26.48471 2016-01-14T09:09:26.484Z 26570 TID-z08uw ActionMailer::DeliveryJob JID-0627de829621f083381e610c INFO: fail: 60.108 sec
2016-01-14_09:09:26.48486 2016-01-14T09:09:26.484Z 26570 TID-z08uw WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"ActionMailer::DeliveryJob", "queue"=>"mailers", "args"=>[{"job_class"=>"ActionMailer::DeliveryJob", "job_id"=>"774f8ba5-6be9-4a1d-8f5b-c4bf4b820473", "queue_name"=>"mailers", "arguments"=>["DeviseMailer", "confirmation_instructions", "deliver_now", {"_aj_globalid"=>"gid://gitlab/User/2"}, "Xi5jzczxST5nd522_dt4", {"_aj_symbol_keys"=>[]}], "locale"=>"en"}], "retry"=>true, "jid"=>"0627de829621f083381e610c", "created_at"=>1452762417.0482812, "enqueued_at"=>1452762506.3762627, "error_message"=>"Net::ReadTimeout", "error_class"=>"Net::ReadTimeout", "failed_at"=>1452762482.5856326, "retry_count"=>1, "retried_at"=>1452762566.4842744}

What’s the matter? Does gmail allows external application to send emails through their servers?

Is better to open a new dedicated thread?

Just another element: if I try to send a test email with swaks, with the following command, from my company smtp server

./swaks --to myemail@gmail.com --from=mycompanyemail@company.it --auth --auth-user=mycompanyemail --auth-password=mycompanyemailpassword --server smtp.company.it

I receive the email to myemail@gmail.com

So, following these parameters, how can I configure gitlab-ce to send confirmation emails using my company smtp server?

Start with:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.company.it"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "mycompanyemail"
gitlab_rails['smtp_password'] = "mycompanyemailpassword"
gitlab_rails['smtp_domain'] = "company.it"
gitlab_rails['smtp_authentication'] = "login"