Greenlight: SMTP sendmail error

Created on 12 May 2020  Â·  10Comments  Â·  Source: bigbluebutton/greenlight

Hi,
I tried to search all the issues and google too but I didn't manage to find a solution.
Like other people
I have the same error running
docker run --rm --env-file .env bigbluebutton/greenlight:v2 bundle exec rake conf:check.

sendmail: default setting with empty fields.

Checking SMTP connection: Failed
Error connecting to SMTP - Connection refused - connect(2) for "" port 

I can successfully send mail trough console like this:

echo "Subject: sendmail test" | sendmail -v [email protected]

obviously ALLOW_MAIL_NOTIFICATIONS=true this is in my env and I tried to ignore the check and register a new user to see if the mail is sended but no luck

Most helpful comment

SMTP BBB/Greenlight in Docker version installed

As Greenlight is running inside a docker image, the sendmail option is not possible as the image does not contain sendmail and/or you can not configure it (docker specialist could help us to understand how to add and configure sendmail on the docker image, but i think this out out scope)

so you have no other option than configure the SMTP_SERVER in your .env file

Then if you want to use the local sendmail/postfix instance running on your BBB server, you will have to :

1 . configure postfix/sendmail to accept to relay mail from the docker image networks

to do that, check ip network range used by the docker image and by your docker bridge.

  • you can do this by running
    docker network ls
    docker network inspect bridge
    docker network inspect greenlight_default

Note : if you don’t see greenlight_default network, start docker image before running the command (docker-compose up -d)

I modify /etc/postfix/main.cf and add in
mynetworks = ….. 192.168.0.0/16 172.17.0.0/16

i was using larger private network range as i notice they change after re-compose, see notes below

if TLS is invoked by greenlight when sending email, i use the same certificate i have for BBB server (pem and key files) and modify the /etc/postfix/main.cf to reflect that
smtpd_tls_cert_file=/etc/letsencrypt/live/xxxxx/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/xxxxx/privkey.pem

systemctl restart postfix

you need also to add the firewall rules for greenlight_network and bridge
For example I add ufw rules to allow connection :
ufw allow from 192.168.0.0/16 to any proto tcp port 25
ufw allow from 172.17.0.0/16 to any proto tcp port 25

you could be more restrictive on the “to any” in your case. same remark regarding larger network as they could change.

Another clean solution would be to configure SMTP_AUTH and allow sending email only from authenticated users and any IP (but for that i let you check postfix/sendmail documentation)

2. configure the SMTP_xxxx directives

  • to match my certificate and avoid TLS Certificate Warning Error, i enter the public dns name of my bbb server in SMTP_SERVER
  • as soon as SMTP_SERVER is not commented out in .env the Greenlight will use the “SMTP” method instead of “sendmail” to send mail from the Ruby and Rail application.
  • so complete the other SMTP_xxxx settings
  • (optional ?)i have also to modify the file /apps/environnments/production.erb to modify the [email protected] to something that my SMTP server could accept

then run the tests to see if you still have the SMTP warning message
docker run --rm --env-file .env bigbluebutton/greenlight:v2 bundle exec rake conf:check
you will see that connection come from bridge network during this test

and the magic did the trick
Checking environment: Passed
Checking Connection: Passed
Checking Secret: Passed
Checking SMTP connection: Passed
You have new mail in /var/mail/root

as you see the test is working and i see in postfix log /var/log/mail that the test mail is sent

so at the end it is only firewall issue and postfix/sendmail adjustment

if you still facing issue, you could install iptraf-ng
sudo apt-get install iptraf-ng
on your bbb server and check if you see port 25 SMTP attempt and from a particular network and adjust your setting to get it working.

be aware that greenlight_network_default change IP range each time you docker-compose down and up so double check IP and adjust large enough

there seems to be a way to fix ip range of a docker image in docker-compose.yml but out of my knowledge (at least at the moment)

PS: this link could help: https://api.rubyonrails.org/classes/ActionMailer/Base.html to understand mail settings

All 10 comments

I'm pretty sure sendmail stopped working sometime around v2.4. Can you try specifying an SMTP server?

Bummer, yeah I tried with an external smtp but it give me errors and sendmail was way more practical.
Btw the error with the provider I should use instead of sendmail

Error connecting to SMTP - Net::ReadTimeout

At this point it seems to me that the only way to make it work is use a google smtp, not a solution that is optimal considering that we pay for a mail service.

Normally this timeout refers to the request being blocked by a firewall or configuration setting. I would check that the mail server accepts incoming requests from the IP of the machine running the docker containers

I tried with google and the configuration passed right away, so should the .env be modified deleting the sendmail part? Or a fix is scheduled?

SMTP BBB/Greenlight in Docker version installed

As Greenlight is running inside a docker image, the sendmail option is not possible as the image does not contain sendmail and/or you can not configure it (docker specialist could help us to understand how to add and configure sendmail on the docker image, but i think this out out scope)

so you have no other option than configure the SMTP_SERVER in your .env file

Then if you want to use the local sendmail/postfix instance running on your BBB server, you will have to :

1 . configure postfix/sendmail to accept to relay mail from the docker image networks

to do that, check ip network range used by the docker image and by your docker bridge.

  • you can do this by running
    docker network ls
    docker network inspect bridge
    docker network inspect greenlight_default

Note : if you don’t see greenlight_default network, start docker image before running the command (docker-compose up -d)

I modify /etc/postfix/main.cf and add in
mynetworks = ….. 192.168.0.0/16 172.17.0.0/16

i was using larger private network range as i notice they change after re-compose, see notes below

if TLS is invoked by greenlight when sending email, i use the same certificate i have for BBB server (pem and key files) and modify the /etc/postfix/main.cf to reflect that
smtpd_tls_cert_file=/etc/letsencrypt/live/xxxxx/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/xxxxx/privkey.pem

systemctl restart postfix

you need also to add the firewall rules for greenlight_network and bridge
For example I add ufw rules to allow connection :
ufw allow from 192.168.0.0/16 to any proto tcp port 25
ufw allow from 172.17.0.0/16 to any proto tcp port 25

you could be more restrictive on the “to any” in your case. same remark regarding larger network as they could change.

Another clean solution would be to configure SMTP_AUTH and allow sending email only from authenticated users and any IP (but for that i let you check postfix/sendmail documentation)

2. configure the SMTP_xxxx directives

  • to match my certificate and avoid TLS Certificate Warning Error, i enter the public dns name of my bbb server in SMTP_SERVER
  • as soon as SMTP_SERVER is not commented out in .env the Greenlight will use the “SMTP” method instead of “sendmail” to send mail from the Ruby and Rail application.
  • so complete the other SMTP_xxxx settings
  • (optional ?)i have also to modify the file /apps/environnments/production.erb to modify the [email protected] to something that my SMTP server could accept

then run the tests to see if you still have the SMTP warning message
docker run --rm --env-file .env bigbluebutton/greenlight:v2 bundle exec rake conf:check
you will see that connection come from bridge network during this test

and the magic did the trick
Checking environment: Passed
Checking Connection: Passed
Checking Secret: Passed
Checking SMTP connection: Passed
You have new mail in /var/mail/root

as you see the test is working and i see in postfix log /var/log/mail that the test mail is sent

so at the end it is only firewall issue and postfix/sendmail adjustment

if you still facing issue, you could install iptraf-ng
sudo apt-get install iptraf-ng
on your bbb server and check if you see port 25 SMTP attempt and from a particular network and adjust your setting to get it working.

be aware that greenlight_network_default change IP range each time you docker-compose down and up so double check IP and adjust large enough

there seems to be a way to fix ip range of a docker image in docker-compose.yml but out of my knowledge (at least at the moment)

PS: this link could help: https://api.rubyonrails.org/classes/ActionMailer/Base.html to understand mail settings

@cedricmm Thank you very much, the detailed tutorial really is a bless.
I successfully configured the postfix connection and the mail arrived correctly. Now I can focus on harden the DKIM configuration and everything to make the mail respectable to providers :D
Again thank you very much for the detailed configuration, it should be on the faq

I think so, it should be in the FAQ, i spent 2 days on it looking for the Ruby and rail code and debugging to finally understand all was ok in the code and that sendmail is unusable if you are in docker image, and that the root issue with SMTP_SERVER is only a network/firewall and postfix configuration issue introduce by the use of docker .So i agree with you, we need some tips in the FAQ for new docker user in order to understand the process. after you understand a bit more how docker is working, this is really more clear how to debug for a "normal " sysadmin. Tips on how to fixe IP upon recompose would be a plus in the documentation to permit better firewall rules.
take care !

@SilverBull Glad you got it working. @cedricmm Thanks for your help and for providing the steps. I'll definitely improve the SMTP docs sometime in the near future with some better steps to configure sendmail/postfix

@farhatahmad, @cedricmm

I guess for me it was simply updating app/config/environments/production.rb and .env

Please find details here -> #1662

Many thanks @cedricmm for your help! I succeeded thanks to your detailed steps saving many hours of research.

Maybe a hint on a _docker-compose.yml_ for fixing IP troubles?

version: '3'

services:
  app:
    entrypoint: [bin/start]
    image: bigbluebutton/greenlight:v2
    container_name: greenlight-v2
    env_file: .env
    restart: unless-stopped
    ports:
      - 127.0.0.1:5000:80
    networks:
      net:
        ipv4_address: 172.16.0.2
# When using external logging
#    logging:
#      driver: $LOG_DRIVER
#      options:
#        syslog-address: $LOG_ADDRESS
#        tag: $LOG_TAG
    volumes:
      - ./log:/usr/src/app/log
      - ./storage:/usr/src/app/storage
# When using sqlite3 as the database
#      - ./db/production:/usr/src/app/db/production
# When using postgresql as the database
    links:
      - db
  db:
    image: postgres:9.5
    restart: unless-stopped
    ports:
      - 127.0.0.1:5432:5432
    networks:
      net:
        ipv4_address: 172.16.0.3
    volumes:
      - ./db/production:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password

networks:
  net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.16.0.0/16

With this one I was finally able to configure postfix to survive container restarts!!

Was this page helpful?
0 / 5 - 0 ratings