从 Java Camel 应用程序连接到 Python 邮件服务器时出现问题
Problem connecting to Python mail server from Java Camel application
我有一个使用 Python 语言 aiosmtpd
包 (https://github.com/aio-libs/aiosmtpd) 实现的简单电子邮件服务器。我还有一个 Apache Camel 应用程序,其路由尝试从服务器获取邮件。
我已经能够成功发送邮件到服务器,并且正在保存到一个目录中。但是,我 运行 在尝试从服务器获取邮件时遇到了问题。来自 Camel 应用程序的错误消息是:
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.access1(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]
邮件服务器没有显示可见消息。我不知道它是否维护某种日志。发送邮件时,服务器会显示很多关于它从发件人那里收到的消息的信息,所以肯定是在显示一些信息。
我不知道用户名应该是什么。另外,用户是否需要密码?我在 aiosmtpd
网站上找不到涉及用户或密码的信息。
是否期望邮件服务器有一组 recognized/authorized 用户并且我需要指定其中一个?有没有不需要一个user/password?
这里是骆驼路线供参考:
<route id="mail-receive">
<from
uri="imap://{{mail-client.server.host}}:{{mail-client.server.port}}?unseen=true&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 脚本:
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 协议用于发送、中继或转发消息,但您不能使用它来接收消息。您需要将您的邮箱应用程序与 IMAP
或 POP3
.
的某些实现相结合
我有一个使用 Python 语言 aiosmtpd
包 (https://github.com/aio-libs/aiosmtpd) 实现的简单电子邮件服务器。我还有一个 Apache Camel 应用程序,其路由尝试从服务器获取邮件。
我已经能够成功发送邮件到服务器,并且正在保存到一个目录中。但是,我 运行 在尝试从服务器获取邮件时遇到了问题。来自 Camel 应用程序的错误消息是:
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.access1(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]
邮件服务器没有显示可见消息。我不知道它是否维护某种日志。发送邮件时,服务器会显示很多关于它从发件人那里收到的消息的信息,所以肯定是在显示一些信息。
我不知道用户名应该是什么。另外,用户是否需要密码?我在 aiosmtpd
网站上找不到涉及用户或密码的信息。
是否期望邮件服务器有一组 recognized/authorized 用户并且我需要指定其中一个?有没有不需要一个user/password?
这里是骆驼路线供参考:
<route id="mail-receive">
<from
uri="imap://{{mail-client.server.host}}:{{mail-client.server.port}}?unseen=true&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 脚本:
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 协议用于发送、中继或转发消息,但您不能使用它来接收消息。您需要将您的邮箱应用程序与 IMAP
或 POP3
.