Notesnook: Self-Hosted Sync Server with SMTP

06-12-2024 - 2 minutes, 20 seconds -
documentation notesnook docker smtp self-hosted

Introduction

Notesnook is a privacy-focused note-taking application that supports self-hosted sync servers. This guide provides a complete setup for deploying the Notesnook Sync Server with Docker, configuring SMTP for email notifications, and ensuring proper server operation using environment variables.


Prerequisites

  1. Docker and Docker Compose installed on your server.
  2. .env file for sensitive environment variables such as SMTP settings and API secrets.
  3. Basic understanding of Docker networking and storage volumes.

Steps to Set Up Notesnook

1. Create a Docker Compose File

The following docker-compose.yml defines the required services for the Notesnook Sync Server, including MongoDB, S3 storage, and other dependencies:

version: '3'

x-server-discovery: &server-discovery
  NOTESNOOK_SERVER_PORT: 8010
  NOTESNOOK_SERVER_HOST: notesnook-server
  IDENTITY_SERVER_PORT: 8011
  IDENTITY_SERVER_HOST: identity-server
  SSE_SERVER_PORT: 8012
  SSE_SERVER_HOST: sse-server
  SELF_HOSTED: 1
  IDENTITY_SERVER_URL: ${AUTH_SERVER_PUBLIC_URL}
  NOTESNOOK_APP_HOST: ${NOTESNOOK_APP_PUBLIC_URL}

x-env-files: &env-files
  - .env

services:
  notesnook-db:
    image: mongo:7.0.12
    hostname: notesnook-db
    volumes:
      - ./db:/data/db
      - ./configdb:/data/configdb
    networks:
      - notesnook
    command: --replSet rs0 --bind_ip_all
    healthcheck:
      test: echo 'db.runCommand("ping").ok' | mongosh mongodb://localhost:27017 --quiet
      interval: 40s
      timeout: 30s
      retries: 3
      start_period: 60s

  notesnook-s3:
    image: minio/minio:latest
    ports:
      - 9000:9000
    networks:
      - notesnook
    volumes:
      - ./s3:/data/s3
    environment:
      MINIO_BROWSER: "on"
    command: server /data/s3 --console-address :9090
    healthcheck:
      test: timeout 5s bash -c ':> /dev/tcp/127.0.0.1/9000' || exit 1
      interval: 40s
      timeout: 30s
      retries: 3
      start_period: 60s

  identity-server:
    image: streetwriters/identity:latest
    ports:
      - 8011:8011
    networks:
      - notesnook
    env_file: *env-files
    environment:
      <<: *server-discovery
      MONGODB_CONNECTION_STRING: mongodb://notesnook-db:27017/identity?replSet=rs0

  notesnook-server:
    image: streetwriters/notesnook-sync:latest
    ports:
      - 8010:8010
    networks:
      - notesnook
    env_file: *env-files
    depends_on:
      - notesnook-s3
      - identity-server
    healthcheck:
      test: wget --tries=1 -nv -q http://localhost:8010/health -O- || exit 1
      interval: 40s
      timeout: 30s
      retries: 3
      start_period: 60s
    environment:
      <<: *server-discovery
      MONGODB_CONNECTION_STRING: mongodb://notesnook-db:27017/?replSet=rs0
      S3_INTERNAL_SERVICE_URL: "http://notesnook-s3:9000"
      S3_BUCKET_NAME: "attachments"

networks:
  notesnook:

2. Configure the .env File

Create a .env file in the same directory as the docker-compose.yml. Replace placeholders with actual values:

INSTANCE_NAME=clint-masden-notesnook-instance
NOTESNOOK_API_SECRET=replace-with-a-long-random-string
DISABLE_ACCOUNT_CREATION=0
SMTP_USERNAME=your-email@example.com
SMTP_PASSWORD=your-smtp-password
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
NOTESNOOK_SENDER_EMAIL=your-email@example.com
SMTP_REPLYTO_EMAIL=your-email@example.com
NOTESNOOK_APP_PUBLIC_URL=http://notesnook.clintmasden.duckdns.org
MONOGRAPH_PUBLIC_URL=http://monogr-notesnook.clintmasden.duckdns.org
AUTH_SERVER_PUBLIC_URL=http://identity-notesnook.clintmasden.duckdns.org
ATTACHMENTS_SERVER_PUBLIC_URL=http://sse-notesnook.clintmasden.duckdns.org

3. Configure SMTP (Gmail Example)

If you're using Gmail for SMTP, ensure you follow these steps:

  1. Enable "Less Secure App Access" in your Google Account settings.
  2. Use an App Password:
    • Generate an App Password to avoid sharing your main account password.
    • Replace the SMTP_PASSWORD in the .env file with the generated App Password.

4. Start the Services

Run the following command to bring up all services:

docker-compose up -d

Resources and References

Links and Summaries


Conclusion

This guide provides a step-by-step walkthrough for deploying Notesnook’s self-hosted sync server with SMTP email notifications. By leveraging Docker, you can ensure a secure and scalable environment for managing notes. Refer to the resources for troubleshooting and further customization.