0

I have a simple email server implemented using the Python language aiosmtpd package (https://github.com/aio-libs/aiosmtpd). I also have an Apache Camel application with a route that attempts to get mail from the server.

I have been able to successfully send mail to the server, and it is being saved to a directory. However I'm running into a problem when attempting to get mail from the server. The error message from the Camel application is:

2020-04-29 10:51:54.476  WARN 17916 --- [/localhost:8025] o.a.c.c.m.MailConsumer                   : Consumer Consumer[imap://localhost:8025?delay=10000&unseen=true] failed polling endpoint: imap://localhost:8025?delay=10000&unseen=true. Will try again at next poll. Caused by: [javax.mail.AuthenticationFailedException - failed to connect, no user name specified?]

javax.mail.AuthenticationFailedException: failed to connect, no user name specified?
    at javax.mail.Service.connect(Service.java:373) ~[jakarta.mail-1.6.4.jar:1.6.4]
    at org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:568) ~[camel-mail-3.1.0.jar:3.1.0]
    at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:126) ~[camel-mail-3.1.0.jar:3.1.0]
    at org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187) [camel-support-3.1.0.jar:3.1.0]
    at org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollConsumer.java:106) [camel-support-3.1.0.jar:3.1.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_241]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_241]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_241]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_241]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_241]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]

The mail server displays no visible messages. I do not know if it maintains a log of some sort. When mail is sent, the server displays lots of information about the message it received from the sender, so it is definitely displaying some information.

I have no idea what the user name should be. Also, does the user require a password? I can't find information on the aiosmtpd site that refers to a user or password.

Is there an expectation that the mail server has a set of recognized/authorized users and that I need to specify one of them? Is there such a thing as not needing a user/password?

Here is the Camel route for reference:

<route id="mail-receive">
  <from
    uri="imap://{{mail-client.server.host}}:{{mail-client.server.port}}?unseen=true&amp;delay=10000" />
  <log loggingLevel="INFO" message="start - mail-receive" />
  <to uri="file:{{mail-client.receive.dest-dir}}" />
  <log loggingLevel="INFO" message="end - mail-receive" />
</route>

And here is the mail server python script:

server.py:

#! /usr/bin/python3

import os
import asyncio
import logging
import tempfile

from aiosmtpd.controller import Controller
from aiosmtpd.handlers import Mailbox


async def mailbox_controller(dir):
    cont = Controller(Mailbox(dir), hostname='', port=8025)
    cont.start()


def main():
    logging.basicConfig(level=logging.DEBUG)

    temp_dir = tempfile.TemporaryDirectory()
    maildir_path = os.path.join(temp_dir.name, 'maildir')

    loop = asyncio.get_event_loop()
    loop.create_task(mailbox_controller(dir=maildir_path))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logging.info('Shutting down')


if __name__ == '__main__':
    main()
Joseph Gagnon
  • 1,731
  • 3
  • 30
  • 63

1 Answers1

2

aiosmtpd is SMTP server. SMTP protocol is used to send, relay or forward messages, but you cannot use it to receive messages. You would need to combine your mailbox application with some implementation of IMAP or POP3.

Bedla
  • 4,789
  • 2
  • 13
  • 27
  • Isn't that what should be happening with the IMAP Camel route? I guess I don't understand. Do you have an example or suggestions of what to look for? – Joseph Gagnon Apr 30 '20 at 11:32
  • 1
    In Camel you have IMAP **client**. You currently have no IMAP **server** (You have only SMTP server) implemented in python, so Camel have no way to connect to. I have no example. I am here because question is tagged with apache-camel, but this is all about your python server. I have no awareness about python ecosystem, so cannot suggest good library or example for IMAP server. – Bedla Apr 30 '20 at 11:40
  • That was helpful. It pointed out to me what SMTP does (and only what it does). – Joseph Gagnon Apr 30 '20 at 12:28