apache-camel - How to write camel blueprint (send email)
问题描述
I'm trying sent mail with apache Camel with xml. So I build postfix , dovecot and servicemix same server. I wrote below xmlfile. but it doesn't work and occur a error
- precondition
- install Mail Component(camel)
- confirm bundle:list(status:active)
Please teach me how to write xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- -->
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- -->
<route>
<from uri="smtp://localhost?from=testuser01@domain?subject=testmail" />
<to uri="pop3://localhost?to=testuser02@domain" />
</route>
</camelContext>
</blueprint>
You can view the error below:
2018-08-06 00:46:44,007 | ERROR | mix-7.0.0/deploy | BlueprintCamelContext | 40 - org.apache.camel.camel-blueprint - 2.16.4 | Error occurred during starting Camel: CamelContext(camel-3) due Protocol smtp cannot be used for a MailConsumer. Please use another protocol such as pop3 or imap.
============================================
@Namphibian Thank you for your quick reply. I fixed the code and retlied , but didn't work.
You can view the error below
・ERROR
WARN | pop3://IPAddress | MailConsumer | 43 - org.apache.camel.camel-core - 2.16.4 | Consumer Consumer[pop3://IPAddress?to=user%40domain] failed polling endpoint: Endpoint[pop3://IPAddress?to=user%40domain]. Will try again at next poll. Caused by: [javax.mail.AuthenticationFailedException - failed to connect, no user name specified?]
I thougut that I need to wirite username and Password, but didn't work
・CODE
<route>
<from uri="pop3://IPaddress?to=user@domain?username=user@domain?password=password" />
<log message="received the message with this content: ${body}" />
<to uri="smtp://IPaddress?from=admin@domain?subject=testmail" />
</route>
You can view the error below
WARN | pop3://IPAddress | MailConsumer | 43 - org.apache.camel.camel-core - 2.16.4 | Consumer Consumer[pop3://IPAddress?to=user%40domain%3Fusername%3Duser%40domain%3Fpassword%3Duser] failed polling endpoint: Endpoint[pop3://IPAddress?to=user%40domain%3Fusername%3Duser%40domain%3Fpassword%3Duser]. Will try again at next poll. Caused by: [javax.mail.AuthenticationFailedException - failed to connect, no user name specified?]
How should I do to send and receive a mail?
============================================
Refixed code and tried again. But didn't work.
・CODE
<route>
<from uri="pop3://IPaddress?to=user@domain?username=user@domain&password=password" />
<log message="received the message with this content: ${body}" />
<to uri="smtp://IPaddress?from=admin@domain?subject=testmail" />
</route>
・ERROR
WARN | pop3://IPAddress | MailConsumer | 43 - org.apache.camel.camel-core - 2.16.4 | Consumer Consumer[pop3://IPAddress?password=xxxxxx&to=user%40domain%3Fusername%3Duser%40domain] failed polling endpoint: Endpoint[pop3://IPAddress?password=xxxxxx&to=user%40domain%3Fusername%3Duser%40domain]. Will try again at next poll. Caused by: [javax.mail.AuthenticationFailedException - [AUTH] Authentication failed.]
IPAddress
I thougut %40 represents @. Should I fix some special charactor?
I find URL that wrote about how to escape special character. But couldn't find bout "@". http://camel.apache.org/how-do-i-use-uris-with-parameters-in-xml.html
解决方案
SMTP 用于发送邮件,POP 用于读取邮件。您不能在路由的 from 部分使用 SMTP 的原因是您没有任何东西可以发送 from。
另一点是您说向 POP 组件发送消息。POP 用于阅读邮件。所以你的路线要求做一个读()写组件(SMTP)。
<from uri="smtp://localhost?from=testuser01@domain?subject=testmail" />
然后您要求 write() 一个读取组件 (POP)。
<to uri="pop3://localhost?to=testuser02@domain" />
如果您颠倒组件的顺序,以便您读取(从)读取组件(POP)并写入(到)到写入组件(SMTP),它可能会起作用。
换句话说:
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="pop3://localhost?to=testuser02@domain" />
<log message="received the message with this content: ${body}"/>
<to uri="smtp://localhost?from=testuser01@domain?subject=testmail" />
</route>
</camelContext>
希望这是有道理的。您的组件顺序错误,它们用于不同的目的,因此顺序很重要。
推荐阅读
- ios - 在 Mac 上为 iOS 构建 libgdx 默认测试项目需要 Android SDK?
- amazon-web-services - 无法通过 cloudformation 设置 cognito userpool 客户端的属性
- db2 - 可以访问 DB2 的用户是否也可以访问 OS400?
- git - phpcs 仅对 git blame 值
- c++ - 在 C++ 中模拟导入作为来自 python 的功能
- riscv - 火箭芯片指令跟踪列
- javascript - 将清晰的文本渲染为 three.js 纹理
- linux - 比较两个文件并应用差异
- ruby - 无法在 IntelliJ for Mac 上安装和使用 Ruby 插件
- web-crawler - 将抓取限制在种子 url 的子页面