如何撰写骆驼蓝图(发送电子邮件)

时间:2018-08-06 03:31:48

标签: apache-camel blueprint apache-camel-mail

我正在尝试使用apache Camel和xml发送邮件。 因此,我在同一服务器上构建了postfix,dovecot和servicemix。 我在xmlfile下面写的。但它不起作用并发生错误

  • 前提条件
  • 安装邮件组件(骆驼)
  • 确认bundle:list(status:active)

请教我如何编写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>

您可以在下面查看错误:

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 感谢您的快速答复。 我修复了代码并退出了,但是没有用。

您可以在下面查看错误

・错误

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?]

我认为我需要输入用户名和密码,但是没有用

・密码

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

您可以在下面查看错误

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?]

我应该如何发送和接收邮件?

==========================================

已修复代码,然后重试。 但是没用。

・密码

<route>                                                                                                         
          <from uri="pop3://IPaddress?to=user@domain?username=user@domain&amp;password=password" />
          <log message="received the message with this content: ${body}" />
          <to uri="smtp://IPaddress?from=admin@domain?subject=testmail" />
</route>

・错误

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

我认为%40代表@。 我应该修复一些特殊字符吗?

我找到了写有关如何转义特殊字符的URL。 但是找不到回合“ @”。 http://camel.apache.org/how-do-i-use-uris-with-parameters-in-xml.html

1 个答案:

答案 0 :(得分:1)

SMTP用于发送邮件,而POP用于读取邮件。您无法在路由的“发件人”部分中使用SMTP的原因是,您无从发件人发送邮件。

另一点是您要向POP组件发送消息。 POP用于读取邮件。因此,您的路线要求执行read()和write组件(SMTP)。

<from uri="smtp://localhost?from=testuser01@domain?subject=testmail" />

然后,您要求写入()一个读取组件(POP)。

<to uri="pop3://localhost?to=testuser02@domain" />

如果反转组件的顺序,以便从readcomponent(POP)读取(POP)并将write(to)写入写入组件(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>

希望如此。您的组件顺序错误,它们具有不同的用途,因此顺序很重要。