Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maildev fails to start when using --auto-relay together with --mail-directory #420

Open
heldchen opened this issue Jun 5, 2022 · 5 comments

Comments

@heldchen
Copy link

heldchen commented Jun 5, 2022

when using the --mail-directory and --auto-relay options together, starting maildev fails as soon as there are on-disk stored mails in the defined mail directory:

MailDev using directory /srv/tools/maildev/
MailDev outgoing SMTP Server mail.intern.somedomain:25 (user:undefined, pass:undefined, secure:no)
Auto-Relay mode on, Relay rules: [{"deny":"*"},{"allow":"text@example.com"}]
MailDev webapp running at http://:::1080
MailDev SMTP Server running at :::1025
/usr/lib/node_modules/maildev/lib/outgoing.js:155
  let recipients = emailObject.envelope.to.map(getAddressFromAddressObject)
                                           ^

TypeError: emailObject.envelope.to.map is not a function
    at relayMail (/usr/lib/node_modules/maildev/lib/outgoing.js:155:44)
    at relayWorker (/usr/lib/node_modules/maildev/lib/outgoing.js:212:3)
    at /usr/lib/node_modules/maildev/node_modules/async/dist/async.js:4011:13
    at Object.process (/usr/lib/node_modules/maildev/node_modules/async/dist/async.js:1674:21)
    at /usr/lib/node_modules/maildev/node_modules/async/dist/async.js:1532:23
    at /usr/lib/node_modules/maildev/node_modules/async/dist/async.js:74:45
    at internal/process/task_queues.js:153:7
    at AsyncResource.runInAsyncScope (async_hooks.js:189:9)
    at AsyncResource.runMicrotask (internal/process/task_queues.js:150:8)
    at runNextTicks (internal/process/task_queues.js:62:5)

it looks like maildev is trying to autorelay the mails in the on-disk store upon starting the service. the service starts when either the local mail store directory is empty or --auto-relay is removed from the startup options.

configurations:

daemon options:

/usr/bin/maildev  --ip :: --smtp 1025 --web 1080 --auto-relay-rules /etc/maildev/relay.json --mail-directory /srv/maildev/ --outgoing-host mail.intern.somedomain.com

/etc/maildev/relay.json:

[
    {
        "deny": "*"
    },
    {
        "allow": "test@example.com"
    
]

reproduced in the latest 2.0.5 version.

repo steps:

  1. use above startup options & configs
  2. send local mail to test@example.com & ensure it's shown in maildev and is stored to /srv/maildev/
  3. restart maildev service
@totallyben
Copy link

Also seeing the same issue

@ahaly-compass
Copy link

Hello is there any solution for this?
I using the version 2.1.0 and the error stil exists

Here is my config to reproduce
compose.yaml

services:
  mailcatcher:
    image: maildev/maildev:2.1.0
    container_name: mailcatcher
    restart: always
    ports:
      - "1080:1080"  # Web interface
      - "1025:1025"  # SMTP server
    volumes:
      - ./mails:/home/maildev/data:rw
      - ./rules.json:/home/maildev/rules.json:ro
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
    networks:
      - mail
    env_file:
      - .env
    command: bin/maildev --auto-relay --mail-directory=/home/maildev/data

networks:
  mail:

.env File

#MAILDEV_MAIL_DIRECTORY=/home/maildev/data

MAILDEV_WEB_PORT=1080
MAILDEV_SMTP_PORT=1025

#MAILDEV_AUTO_RELAY=true # not working because maildev can't handle boolean in env files, use the command option instead
MAILDEV_AUTO_RELAY_RULES=/home/maildev/rules.json

MAILDEV_OUTGOING_HOST=xxx
MAILDEV_OUTGOING_PORT=xxx
MAILDEV_OUTGOING_USER=xx
MAILDEV_OUTGOING_PASS=xx

@jeandonaldroselin
Copy link

jeandonaldroselin commented Jan 7, 2024

For thoses facing this issue, the temporary solution I found is to :

1 - Fix the outgoing.js file by replacing line 155 with :

let recipients = emailObject?.envelope?.to ? emailObject.envelope.to.map(getAddressFromAddressObject) : [];

I will raise a PR soon with this fix.

2 - Add the outgoing.js file as a volume for the maildev container :

docker-compose.yml file :

services:
  maildev:
    image: maildev/maildev:2.1.0
    restart: always
    ports:
      - "1080:1080"  # Web interface
    volumes:
      - ./mails:/home/node/mails
      - ./outgoing.js:/home/node/lib/outgoing.js
    command: bin/maildev
        --web 1080
        --smtp 1025
        --outgoing-host '${OUTGOING_HOST}'
        --outgoing-port '${OUTGOING_PORT}'
        --outgoing-user '${OUTGOING_USER}'
        --outgoing-pass '${OUTGOING_PASS}'
        --web-user '${WEB_USER}'
        --web-pass '${WEB_PASS}'
        --mail-directory '/home/node/mails'
        --auto-relay
        --outgoing-secure
    env_file:
      - .env

.env file :

WEB_USER=x
WEB_PASS=x
OUTGOING_HOST=x
OUTGOING_PORT=x
OUTGOING_USER=x
OUTGOING_PASS=x

@caot
Copy link

caot commented Mar 7, 2024

Need to remove the emails under --mail-directory to fix the error of TypeError: emailObject.envelope.to.map is not a function. It seems not a good option. The --auto-relay --auto-relay-rules worked.

@jeandonaldroselin
Copy link

Need to remove the emails under --mail-directory to fix the error of TypeError: emailObject.envelope.to.map is not a function. It seems not a good option. The --auto-relay --auto-relay-rules worked.

I use the above workaround for two months now on 3 projects rimunning with maildev and it works prperly event after many deployments.

#420 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants