从Java Camel应用程序连接到Python邮件服务器时出现问题 [英] Problem connecting to Python mail server from Java Camel application

查看:129
本文介绍了从Java Camel应用程序连接到Python邮件服务器时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Python语言aiosmtpd包实现的简单电子邮件服务器( https://github .com/aio-libs/aiosmtpd ).我还有一个Apache Camel应用程序,其路由尝试从服务器获取邮件.

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.

我已经能够成功将邮件发送到服务器,并且该邮件已保存到目录中.但是,尝试从服务器获取邮件时遇到了问题.来自Camel应用程序的错误消息是:

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.

我不知道用户名应该是什么.另外,用户是否需要密码?我在aiosmtpd网站上找不到涉及用户或密码的信息.

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>

这是邮件服务器python脚本:

And here is the mail server python script:

server.py:

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()

推荐答案

aiosmtpd是SMTP服务器. SMTP协议用于发送,中继或转发邮件,但是您不能使用它来接收邮件.您需要将您的邮箱应用程序与IMAPPOP3的某些实现组合.

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.

这篇关于从Java Camel应用程序连接到Python邮件服务器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆