calcom / docker

The Docker configuration for Cal.com is an effort powered by people within the community. Cal.com, Inc. does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.
MIT License
646 stars 338 forks source link

SMTP sendEmail error #269

Closed vitis586 closed 1 year ago

vitis586 commented 1 year ago

Hi guys,

I finally got it kind of a running now I am struggling with SMTP. I have all the keys in the .env file.

# E-mail settings
# Configures the global From: header whilst sending emails.
EMAIL_FROM=noreply@example.cz

# Configure SMTP settings (@see https://nodemailer.com/smtp/).
EMAIL_SERVER_HOST=smtp.eu.mailgun.org
EMAIL_SERVER_PORT=465
EMAIL_SERVER_USER=postmaster@example.cz
EMAIL_SERVER_PASSWORD=pass

It seems that the container is not picking the EMAIL_FROM from the .env because the SMTP server refuses to sent mail from notifications@example.com which I understand as I have SPF set up. I already tried starting over - deleting database and renew the secrets.

@calcom/web:start: sendEmail Error: Mail command failed: 550 5.1.0 <notifications@example.com> sender rejected
@calcom/web:start:     at SMTPConnection._formatError (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:787:19)
@calcom/web:start:     at SMTPConnection._actionMAIL (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:1569:34)
@calcom/web:start:     at SMTPConnection.<anonymous> (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:1044:18)
@calcom/web:start:     at SMTPConnection._processResponse (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:950:20)
@calcom/web:start:     at SMTPConnection._onData (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:752:14)
@calcom/web:start:     at SMTPConnection._onSocketData (/calcom/node_modules/nodemailer/lib/smtp-connection/index.js:191:44)
@calcom/web:start:     at TLSSocket.emit (node:events:513:28)
@calcom/web:start:     at addChunk (node:internal/streams/readable:324:12)
@calcom/web:start:     at readableAddChunk (node:internal/streams/readable:297:9)
@calcom/web:start:     at Readable.push (node:internal/streams/readable:234:10)
@calcom/web:start:     at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
@calcom/web:start:   code: 'EENVELOPE',
@calcom/web:start:   response: '550 5.1.0 <notifications@example.com> sender rejected',
@calcom/web:start:   responseCode: 550,
@calcom/web:start:   command: 'MAIL FROM'
@calcom/web:start: }

I looked for similar issues and only found https://github.com/calcom/docker/issues/80 being somewhat close but that was closed due to inactivity.

vitis586 commented 1 year ago

No idea why, but I had to move the EMAIL_FROM from the .env to the container variables. So this is how my sender looks in .env:

# E-mail settings
# Configures the global From: header whilst sending emails.
#EMAIL_FROM=noreply@example.cz

The rest of the email config is still in .env stayed in the .env

# Configure SMTP settings (@see https://nodemailer.com/smtp/).
EMAIL_SERVER_HOST=smtp.eu.mailgun.org
EMAIL_SERVER_PORT=465
EMAIL_SERVER_USER=postmaster@example.cz
EMAIL_SERVER_PASSWORD=pass

I had to do the same with the database connection details so that is where I got my idea from.

krumware commented 1 year ago

Can you help me understand what you mean by the container variables versus the .env in your case? What's your method of running/orchestrating the image? Are you relying on your .env being packaged with the image, versus provided the .env vars at runtime via docker-compose or other orchestrator?

Should help us provide better guidance overall!

vitis586 commented 1 year ago

Sure. Let me try. I am running containers in Docker on Unraid so there is no Compose available. When starting a container there is a form that you fill in and that is then composed into a docker run command:

docker run
  -d
  --name='calcom'
  --net='proxynet'
  -e TZ="Europe/Budapest"
  -e HOST_OS="Unraid"
  -e HOST_HOSTNAME="ClearSky"
  -e HOST_CONTAINERNAME="calcom"
  -e 'DATABASE_URL'='postgresql://calcom:pass@clearsky.hloub/calcom'
  -e 'EMAIL_FROM'='noreply@example.cz'
  -e 'NEXTAUTH_URL'='https://booking.example.cz'
  -l net.unraid.docker.managed=dockerman
  -l net.unraid.docker.webui='http://[IP]:[PORT:3000]'
  -l net.unraid.docker.icon='https://i.imgur.com/mwmNzNQ.png'
  -p '3003:3000/tcp'
  -v '/mnt/cache/appdata/calcom/':'/cal':'rw'
  --env-file /mnt/cache/appdata/calcom/.env 'calcom/cal.com:latest' 

I am running the latest Cal.com version. As you can see, some of the environment variables are passed directly and some through the .env file. There might be a term for this, but you get the point. Initially I had everything in the .env file because it is what the image authors suggested. The container could not connect to database when I had the connection detail in the .env file so I moved those details to the DATABASE_URL variable and that worked. I did the same now with the EMAIL_FROM.

To answer your question directly. I am actually doing both - relying on .env passed as an extra parameter and providing the env variables at runtime. I do not know why it is working that way for me. I wanted to have everything in place but it was not working for me.

I hope I got it right. I am doing this for years now but still only scratching the surface. I am still sorting one last issue. I cannot log in at all after logging out. I am getting just [ERROR] (next-collect/server) - Invalid URL TypeError [ERR_INVALID_URL]: Invalid URL. I am able to pass the login screen with a private browser window (empty browser profile) but then I am not passing the 2FA with the same error code.