toeverything / AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
https://affine.pro
Other
40.9k stars 2.65k forks source link

​Failed to send invite email #5946

Closed fish-uncle closed 1 month ago

fish-uncle commented 7 months ago

What happened?

services:
  affine:
    image: ghcr.io/toeverything/affine-graphql:canary
    container_name: affine_selfhosted
    command:
      ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
    ports:
      - '3010:3010'
      - '5555:5555'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
    volumes:
      # custom configurations
      - /volume1/docker/affine/config:/root/.affine/config
      # blob storage
      - /volume1/docker/affine/storage:/root/.affine/storage
    #logging:
      #driver: 'json-file'
      #options:
        #max-size: '1000m'
    restart: unless-stopped
    environment:
      #- NODE_OPTIONS=--es-module-specifier-resolution=node
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_ADMIN_EMAIL=***
      - AFFINE_ADMIN_PASSWORD=***
      #- SERVER_FLAVOR=selfhosted
  redis:
    image: redis
    container_name: affine_redis
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/redis:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
  postgres:
    image: postgres
    container_name: affine_postgres
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U affine']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: affine
      POSTGRES_PASSWORD: affine
      POSTGRES_DB: affine
      PGDATA: /var/lib/postgresql/data/pgdata

i use admin user login success i want to invite some one friend error

{
    "errors": [
        {
            "message": "Failed to send invite email. Please try again.",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "invite"
            ],
            "extensions": {
                "code": 500,
                "status": "INTERNAL_SERVER_ERROR"
            }
        }
    ],
    "data": null
}

Distribution version

Linux

What browsers are you seeing the problem on if you're using web version?

Chrome

Relevant log output

No response

Anything else?

By the way, I see that AFFiNE Cloud storage is 10GB, and there is a storage limit for self hosted?

Are you willing to submit a PR?

EYHN commented 7 months ago

You should need to configure the mail service on the selfhost docker, we are preparing a document about this.

fish-uncle commented 7 months ago

By the way, I see that AFFiNE Cloud storage is 10GB, and there is a storage limit for self hosted?

EYHN commented 7 months ago

selfhost should have unlimited storage.

I haven't tested it yet, but if you encounter storage size limitations it should be a bug and you can open an issue.

ecker00 commented 7 months ago

I was able to complete this just using the GraphQL API, but it requires quite a bit of tinkering to do. Looking forward to the email documentation is completed. In short if anybody else needs it:

https://localhost:3010/graphql

Go to settings and enable:

  "request.credentials": "include"

This makes cookies work in the playground so you can login and do operations.

Sign up with a second account:

mutation {
     signUp(email: "second@example.com", name: "Second", password: "123") {
         id
     }
}

Sign into the first account and create an invite

mutation {
  signIn(email: "first@example.com", password:"123") {
    id
    name
  }
}

Find your workspace ID, in the browser make sure it's cloud synced then copy the id in the url http://localhost/workspace/<id>/

Then create an invite, this will return an ID, take note of it

mutation {
  invite(
    email: "second@example.com"
    permission: Admin
    sendInviteMail: false
    workspaceId: "xxx-xxx-xx-xxx-xxx"
  )
}

Sign into the second account

mutation {
  signIn(email: "second@example.com", password:"123") {
    id
    name
  }
}

Then accept the invite

mutation {
  acceptInviteById(
    inviteId: "copy-id-from-invite-mutation"
    sendAcceptMail: false
    workspaceId: "your-workspace-id"
  )
}

Anyway, that was my approach for now.

krakowski commented 7 months ago

It's actually quite simple to configure the mailing service. After deployment, I took a look inside the configuration directory which includes a file named affine.env.js containing all possible environment variable keys. Here's the section responsible for getting the SMTP config:

    MAILER_HOST: 'mailer.host',
    MAILER_PORT: ['mailer.port', 'int'],
    MAILER_USER: 'mailer.auth.user',
    MAILER_PASSWORD: 'mailer.auth.pass',
    MAILER_SENDER: 'mailer.from.address',
    MAILER_SECURE: ['mailer.secure', 'boolean'],

So you just need to pass in these environment variables during startup and all should be good.

Jycreyn commented 6 months ago

It's actually quite simple to configure the mailing service. After deployment, I took a look inside the configuration directory which includes a file named affine.env.js containing all possible environment variable keys. Here's the section responsible for getting the SMTP config:

    MAILER_HOST: 'mailer.host',
    MAILER_PORT: ['mailer.port', 'int'],
    MAILER_USER: 'mailer.auth.user',
    MAILER_PASSWORD: 'mailer.auth.pass',
    MAILER_SENDER: 'mailer.from.address',
    MAILER_SECURE: ['mailer.secure', 'boolean'],

So you just need to pass in these environment variables during startup and all should be good.

Hi, I tried your solution but not working for me. I want to configure gmail. image image

Can you help me ?

yurisasc commented 6 months ago

@Jycreyn I managed to get the mailing service working with Gmail.

You have the MAILER_HOST and MAILER_PORT correct. MAILER_USER needs to be your email address MAILER_PASSWORD is the app password that I set using this docs: https://support.google.com/accounts/answer/185833?hl=en I didn't have to set MAILER_SENDER.

Jycreyn commented 6 months ago

@yurisasc

Yeah, I used app password. You did not use "MAIL_SECURE" either ?

thanks

yurisasc commented 6 months ago

@Jycreyn no, I didn't

Jycreyn commented 6 months ago

@yurisasc

you left spaces in the password ?

yurisasc commented 6 months ago

@Jycreyn no, the password should be the 16 digits characters without spaces.

Jycreyn commented 6 months ago

@yurisasc

image

And not working

password is the 16 digit without the spacesn user is my email.

Anything wrong ?

Need to add something in docker compose ?

yurisasc commented 6 months ago

@Jycreyn did you add those environment variable to your docker compose file? It should look like this for the environment variable of the affine container:

    environment:
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_ADMIN_EMAIL=${AFFINE_ADMIN_EMAIL}
      - AFFINE_ADMIN_PASSWORD=${AFFINE_ADMIN_PASSWORD}
      - AFFINE_SERVER_HOST=${AFFINE_SERVER_HOST}
      - AFFINE_SERVER_PORT=${AFFINE_SERVER_PORT}
      - AFFINE_SERVER_HTTPS=${AFFINE_SERVER_HTTPS}
      - MAILER_HOST=${MAILER_HOST}
      - MAILER_PORT=${MAILER_PORT}
      - MAILER_USER=${MAILER_USER}
      - MAILER_PASSWORD=${MAILER_PASSWORD}
Jycreyn commented 6 months ago

@yurisasc

Mhh no, i forgot to put it in docker compose. fck me ...

I see "affine server https" u managed to put it in HTTPS without reverse proxy ?

Jycreyn commented 6 months ago

@yurisasc

Okay mailer is working I can invite people !!

Thank you !

I'm missing something about HTTPS, i put the AFFINE_SERVER_HTTPS to true but not working; SSL error it's still in HTTP. What do i need to add ? image

And also maybe you know, i can only have 3 members ? even in self host ? and for storage the same limited to 10gb in self?

Again thank you so much for you'r help

yurisasc commented 6 months ago

@Jycreyn Ah, I forgot to exclude those variables in my example. AFFINE_SERVER_HOST, AFFINE_SERVER_PORT, and AFFINE_SERVER_HTTPS are extra variables that I added myself and are not related to the mailing service.

To answer your question, yes. I use Cloudflared to expose my AFFiNE container publicly using my own domain, and it works with HTTPS; hence the extra variables above. It is out of the topic of this issue, so I will just add the docs here.

https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/

yurisasc commented 6 months ago

@Jycreyn As for the members limit, I only added one other member and haven't added more. You can try adding more and let me know how it goes :). Also, I'm not sure about the storage limit.

fish-uncle commented 6 months ago

It's actually quite simple to configure the mailing service. After deployment, I took a look inside the configuration directory which includes a file named affine.env.js containing all possible environment variable keys. Here's the section responsible for getting the SMTP config:

    MAILER_HOST: 'mailer.host',
    MAILER_PORT: ['mailer.port', 'int'],
    MAILER_USER: 'mailer.auth.user',
    MAILER_PASSWORD: 'mailer.auth.pass',
    MAILER_SENDER: 'mailer.from.address',
    MAILER_SECURE: ['mailer.secure', 'boolean'],

So you just need to pass in these environment variables during startup and all should be good.

you sure these configuration items are included? didn't see it in this link https://docs.affine.pro/docs/self-host-affine

yurisasc commented 6 months ago

you sure these configuration items are included? didn't see it in this link https://docs.affine.pro/docs/self-host-affine

Yes, those are the environment variables accessed by the app. We can add that to the container environment variables, and the app will be able to use them. We just need to add those in the docs, as it seems like it's still in progress.

EYHN commented 6 months ago

We have a new document about all configurable environment variables.

https://docs.affine.pro/docs/self-host-affine/run-affine-with-custom-options

fish-uncle commented 6 months ago
services:
  affine:
    image: ghcr.io/toeverything/affine-graphql:canary
    container_name: affine_selfhosted
    command:
      ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
    ports:
      - '3010:3010'
      - '5555:5555'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
    volumes:
      # custom configurations
      - /volume1/docker/affine/config:/root/.affine/config
      # blob storage
      - /volume1/docker/affine/storage:/root/.affine/storage
    #logging:
      #driver: 'json-file'
      #options:
        #max-size: '1000m'
    restart: unless-stopped
    environment:
      #- NODE_OPTIONS=--es-module-specifier-resolution=node
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_SERVER_HTTPS=false
      - AFFINE_ADMIN_EMAIL=***
      - AFFINE_ADMIN_PASSWORD=***
      #- SERVER_FLAVOR=selfhosted
      - MAILER_HOST=smtp.163.com
      - MAILER_PORT=25
      - MAILER_USER=***
      - MAILER_PASSWORD=***
  redis:
    image: redis
    container_name: affine_redis
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/redis:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
  postgres:
    image: postgres
    container_name: affine_postgres
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U affine']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: affine
      POSTGRES_PASSWORD: affine
      POSTGRES_DB: affine
      PGDATA: /var/lib/postgresql/data/pgdata

send email error

{
    "errors": [
        {
            "message": "Failed to send invite email. Please try again.",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "invite"
            ],
            "extensions": {
                "code": 500,
                "status": "INTERNAL_SERVER_ERROR"
            }
        }
    ],
    "data": null
}

use /graphql same error

EYHN commented 6 months ago

@fish-uncle Sorry for the late reply.

According to this error, there may be a issue with your email configuration.

Are there any relevant error logs on the server?

Use docker compose tail to check the server logs.

darkskygit commented 6 months ago
services:
  affine:
    image: ghcr.io/toeverything/affine-graphql:canary
    container_name: affine_selfhosted
    command:
      ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
    ports:
      - '3010:3010'
      - '5555:5555'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
    volumes:
      # custom configurations
      - /volume1/docker/affine/config:/root/.affine/config
      # blob storage
      - /volume1/docker/affine/storage:/root/.affine/storage
    #logging:
      #driver: 'json-file'
      #options:
        #max-size: '1000m'
    restart: unless-stopped
    environment:
      #- NODE_OPTIONS=--es-module-specifier-resolution=node
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_SERVER_HTTPS=false
      - AFFINE_ADMIN_EMAIL=***
      - AFFINE_ADMIN_PASSWORD=***
      #- SERVER_FLAVOR=selfhosted
      - MAILER_HOST=smtp.163.com
      - MAILER_PORT=25
      - MAILER_USER=***
      - MAILER_PASSWORD=***
  redis:
    image: redis
    container_name: affine_redis
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/redis:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
  postgres:
    image: postgres
    container_name: affine_postgres
    restart: unless-stopped
    volumes:
      - /volume1/docker/affine/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U affine']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: affine
      POSTGRES_PASSWORD: affine
      POSTGRES_DB: affine
      PGDATA: /var/lib/postgresql/data/pgdata

send email error

{
    "errors": [
        {
            "message": "Failed to send invite email. Please try again.",
            "locations": [
                {
                    "line": 3,
                    "column": 3
                }
            ],
            "path": [
                "invite"
            ],
            "extensions": {
                "code": 500,
                "status": "INTERNAL_SERVER_ERROR"
            }
        }
    ],
    "data": null
}

use /graphql same error

I noticed that you are using a consumer-grade email provider.

For this type of email provider (including gmail, outlook, etc.), if you want to directly use the username-password method, you need to generate an "application-specific password".

For Google , you can generate here: https://myaccount.google.com/apppasswords

For other email providers, you may need to find related options in the settings

vitaaaaa1 commented 5 months ago

Just me,I have set up email information in my configuration file and environment variables in my dockercompose file, but why does my mail function keep reporting errors ”but successfully revoked permission: Error: Mailer service is not configured“ vim ~/.affine/self-host/config/affine.env.js AFFINE_SERVER_PORT: ['port', 'int'], AFFINE_SERVER_HOST: 'host', AFFINE_SERVER_SUB_PATH: 'path', AFFINE_SERVER_HTTPS: ['https', 'boolean'], DATABASE_URL: 'db.url', ENABLE_CAPTCHA: ['auth.captcha.enable', 'boolean'], CAPTCHA_TURNSTILE_SECRET: ['auth.captcha.turnstile.secret', 'string'], OAUTH_GOOGLE_CLIENT_ID: 'plugins.oauth.providers.google.clientId', OAUTH_GOOGLE_CLIENT_SECRET: 'plugins.oauth.providers.google.clientSecret', OAUTH_GITHUB_CLIENT_ID: 'plugins.oauth.providers.github.clientId', OAUTH_GITHUB_CLIENT_SECRET: 'plugins.oauth.providers.github.clientSecret', MAILER_HOST: 'smtp.qq.com', MAILER_PORT: ['465', 'int'], MAILER_USER: '510641286@qq.com', MAILER_PASSWORD: 'fasdfdasfasdff', MAILER_SENDER: 'mailer.from.address', THROTTLE_TTL: ['rateLimiter.ttl', 'int'], THROTTLE_LIMIT: ['rateLimiter.limit', 'int'], REDIS_SERVER_HOST: 'plugins.redis.host', REDIS_SERVER_PORT: ['plugins.redis.port', 'int'], REDIS_SERVER_USER: 'plugins.redis.username', REDIS_SERVER_PASSWORD: 'plugins.redis.password', REDIS_SERVER_DATABASE: ['plugins.redis.db', 'int'], DOC_MERGE_INTERVAL: ['doc.manager.updatePollInterval', 'int'], DOC_MERGE_USE_JWST_CODEC: [ 'doc.manager.experimentalMergeWithYOcto', 'boolean', ],

vim compose.yaml affine: image: ghcr.io/toeverything/affine-graphql:stable container_name: affine_selfhosted command: ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js'] ports:

YourDaniel commented 4 months ago

Hello, guys, it seems that old method to add users no longer working. I can't call SignUp anymore, there's no such mutation in API. How do you add users now via GraphQL?

Meabo commented 4 months ago

Would love to know, can't invite anyone to my workspace :(

AndyPro720 commented 3 months ago

@Jycreyn @yurisasc Struggling from a while, I put the value in the .env file and compose as links to them but it says mailer service not configured. The variables are also not being read from some reason, says variable is empty even though its populated.

Populating the values in the compose file doesn't help either. Could you please help?

thomasaull commented 3 months ago

@AndyPro720 I think affine currently does not read a .env file by itself, you'll have to do the following (at least it works for me this way)

  1. Populate your .env with the variables you want to use, for example:
    MAILER_HOST=my-host.com
    MAILER_PORT=465
    MAILER_USER=me@my-email.com
    MAILER_SENDER=me@my-email.com
    MAILER_SECURE=true
  2. Pass the variables to the affine service in docker-compose.yml:
    [...]
    environment:
    - MAILER_HOST=${MAILER_HOST}
    - MAILER_PORT=${MAILER_PORT}
    - MAILER_USER=${MAILER_USER}
    - MAILER_PASSWORD=${MAILER_PASSWORD}
  3. This might not be necessary if your file is named .env but it doesn't hurt to be specific: Start your service with the --env-file parameter:
    docker compose --file docker-compose.yml --env-file .env up

For debugging, you can run

docker compose --file docker-compose.yml --env-file .env config

this should print out your "resolved" config file → the variables from the .env file should show up here

AndyPro720 commented 3 months ago

@thomasaull Thank you so much for your detailed reply! So as it turns out, on finder reading, docker compose reads env files only in the same directory hence, it wasn't fetching the values. I did that and create an env file and while it doesn't throw any error on starting the container, the mail server not configured error still persists.

Any Ideas? Just to confirm, the app password generated from gmail has to typed in no spaces right?

thomasaull commented 3 months ago

@AndyPro720 Unfortunately I'm out of ideas then, it did work for me after I set it up like in my previous reply. In some cases (don't ask me exactly which ones) you'll need to put your values in quotes in your .env file, I had issues with this in the past. Anything with spaces and certain special characters I guess, maybe for debugging just put everything in quotes. Example:

MAILER_PASSWORD="my password @#$*)&$@"
AndyPro720 commented 3 months ago

@thomasaull Thanks, didn't work unfortunately.

Any idea where to find more details on the error

WARN [WorkspaceResolver] failed to send 8efdcb1c-4534-447b-8a0c-2cb3aa181f90 invite email to angaj.pfchb19@sinhgad.edu, but successfully revoked permission: Error: Mailer service is not configured.

thomasaull commented 3 months ago

@AndyPro720 If I remember correctly I had the same error, but I didn’t do anything special except changing my port I think, so maybe double-check if your values are correct. Those are the variables I put in my .env:

MAILER_HOST=
MAILER_PORT=
MAILER_USER=
MAILER_SENDER=
MAILER_SECURE=
MAILER_PASSWORD=
AndyPro720 commented 3 months ago

@thomasaull Thanks. On adding the sender and secure variables, which were mentioned as not needed up top, seems like there's some progress but I'm still not sure in which direction

Error: connect ECONNREFUSED 127.0.0.1:465

thomasaull commented 3 months ago

@AndyPro720 Are you comfortable sharing your settings (except the password of course)?

AndyPro720 commented 3 months ago

@thomasaull Sure, I'll purge them later. Btw I tested the same settings on Immich's mail server, and it works fine!

.env file

MAILER_HOST=smtp.gmail.com
MAILER_PORT=587
MAILER_USER=trancidence@gmail.com
MAILER_PASSWORD=redacted
MAILER_SENDER=trancidence@gmail.com
MAILER_SECURE=true
AFFINE_SERVER_HOST=192.168.1.10
AFFINE_SERVER_PORT=3010
AFFINE_SERVER_HTTPS=true
# DATABASE_URL="postgres://affine@localhost:5432/affine

compose file image

darkskygit commented 3 months ago

@thomasaull Thank you so much for your detailed reply! So as it turns out, on finder reading, docker compose reads env files only in the same directory hence, it wasn't fetching the values. I did that and create an env file and while it doesn't throw any error on starting the container, the mail server not configured error still persists.

Any Ideas? Just to confirm, the app password generated from gmail has to typed in no spaces right?

as my known, outlook and gmail's app password not include any space and symbol

thomasaull commented 3 months ago

@AndyPro720 Hmm maybe try port 25 or 465 for good measure. Otherwise I'm really out of ideas now :D

AndyPro720 commented 3 months ago

@thomasaull Thanks for all the support.

Gmail smtp has two ports, doesn't work on either :-(

On a general search of this error(node mailers), it seems it occurs when the host isn't resolving to the domain ip, as in this case it seems to be going to localhost 127... and throwing error.

I've looked at a few solutions, but after hours of debugging I'm tired. Let someone from the core team figure this one out. @EYHN

yuchanns commented 3 months ago

I have successfully set up the email service using Gmail. @AndyPro720's configuration is mostly good, except for 2 points:

MAILER_HOST=smtp.gmail.com
MAILER_PORT=465 // <-- use SSL instead,
MAILER_USER=trancidence@gmail.com
MAILER_PASSWORD="16-digit passcode" // <-- an app password created from Google Account. FYI: https://support.google.com/accounts/answer/185833
MAILER_SENDER=trancidence@gmail.com
MAILER_SECURE=true
AFFINE_SERVER_HOST=192.168.1.10
AFFINE_SERVER_PORT=3010
AFFINE_SERVER_HTTPS=true

Hope this helps.

By the way, the documentation is very unclear.

image

AndyPro720 commented 3 months ago

@yuchanns Thanks for the response. I did use SSL port, it is 465. I tried the alt 587 too. I'm also already using app passwords generated from Google, it still isn't working. :^(

rogerc66 commented 2 months ago

it just doesnt work after tried all solutions above

come25136 commented 1 month ago

I had the same error, but I solved it by doing the following:

  1. Pull the canary branch (https://github.com/toeverything/AFFiNE/commit/d82f4b546104443b1467b38f0c626bee7dd62db8)
  2. Add the following to ./.github/deployment/self-host/compose.yaml. The position is the affine container environment.
    - MAILER_HOST=${MAILER_HOST}
    - MAILER_PORT=${MAILER_PORT}
    - MAILER_USER=${MAILER_USER}
    - MAILER_PASSWORD=${MAILER_PASSWORD}
    - MAILER_SENDER=${MAILER_SENDER}
    - MAILER_SECURE=${MAILER_SECURE}
    full config
services:
  affine:
    image: ghcr.io/toeverything/affine-graphql:stable
    container_name: affine_selfhosted
    command:
      ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
    ports:
      - '3010:3010'
      - '5555:5555'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
    volumes:
      # custom configurations
      - ~/.affine/self-host/config:/root/.affine/config
      # blob storage
      - ~/.affine/self-host/storage:/root/.affine/storage
    logging:
      driver: 'json-file'
      options:
        max-size: '1000m'
    restart: unless-stopped
    environment:
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_ADMIN_EMAIL=${AFFINE_ADMIN_EMAIL}
      - AFFINE_ADMIN_PASSWORD=${AFFINE_ADMIN_PASSWORD}
      # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
      - MAILER_HOST=${MAILER_HOST}
      - MAILER_PORT=${MAILER_PORT}
      - MAILER_USER=${MAILER_USER}
      - MAILER_PASSWORD=${MAILER_PASSWORD}
      - MAILER_SENDER=${MAILER_SENDER}
      - MAILER_SECURE=${MAILER_SECURE}
      # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
      # Telemetry allows us to collect data on how you use the affine. This data will helps us improve the app and provide better features.
      # Uncomment next line if you wish to quit telemetry.
      # - TELEMETRY_ENABLE=false
  redis:
    image: redis
    container_name: affine_redis
    restart: unless-stopped
    volumes:
      - ~/.affine/self-host/redis:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
  postgres:
    image: postgres
    container_name: affine_postgres
    restart: unless-stopped
    volumes:
      - ~/.affine/self-host/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U affine']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: affine
      POSTGRES_PASSWORD: affine
      POSTGRES_DB: affine
      PGDATA: /var/lib/postgresql/data/pgdata

  1. Create a .env file in the project root and add the following. https://github.com/toeverything/AFFiNE/issues/5946#issuecomment-2166027131

https://myaccount.google.com/apppasswords

MAILER_HOST=smtp.gmail.com
MAILER_PORT=465 // <-- use SSL instead,
MAILER_USER=google@gmail.com // <-- your gmail account id
MAILER_PASSWORD="16-digit passcode" // <-- an app password created from Google Account. FYI: https://support.google.com/accounts/answer/185833
MAILER_SENDER=google@gmail.com  // <-- your gmail account id
MAILER_SECURE=true
  1. Start the container It is important to add --env-file .env.
    AFFINE_ADMIN_EMAIL="your email" AFFINE_ADMIN_PASSWORD="your password" docker compose -f ./.github/deployment/self-host/compose.yaml --env-file .env up