第一次在javaeye上写博客 过去都是在csdn上写的 写的那里不好请大家多多指教 呵呵
今年做了一个项目 其中一个环节是定时收取邮件然后进行持久化 发现如果使用mule相当简单 不多说了 给大家看看代码吧
pop_config.xml
意思是将我邮箱里的信读入 然后通过component进行业务处理 最后用file进行输出 简单的很
下面看看com.muleinaction.Test吧 也是超级简单:
这样运行后就可以进行邮件收取了
今年做了一个项目 其中一个环节是定时收取邮件然后进行持久化 发现如果使用mule相当简单 不多说了 给大家看看代码吧
pop_config.xml
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:file="http://www.mulesource.org/schema/mule/file/2.1"
xmlns:pop3="http://www.mulesource.org/schema/mule/pop3/2.1"
xmlns:email="http://www.mulesource.org/schema/mule/email/2.1"
xmlns:xm="http://www.mulesource.org/schema/mule/xml/2.1"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd
http://www.mulesource.org/schema/mule/file/2.1 http://www.mulesource.org/schema/mule/file/2.1/mule-file.xsd
http://www.mulesource.org/schema/mule/pop3/2.1 http://www.mulesource.org/schema/mule/pop3/2.1/mule-pop3.xsd
http://www.mulesource.org/schema/mule/email/2.1 http://www.mulesource.org/schema/mule/email/2.1/mule-email.xsd
http://www.mulesource.org/schema/mule/xml/2.1 http://www.mulesource.org/schema/mule/xml/2.1/mule-xml.xsd
http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd"
>
<global-property name="pop3.host" value="pop3.126.com"/>
<global-property name="pop3.port" value="110"/>
<global-property name="pop3.user" value="******"/>
<global-property name="pop3.password" value="*******"/>
<model name="pop3Model">
<service name="pop3Service">
<inbound>
<pop3:inbound-endpoint host="${pop3.host}" port="${pop3.port}" user="${pop3.user}" password="${pop3.password}">
</pop3:inbound-endpoint>
</inbound>
<component class="com.muleinaction.Test"/>
<outbound>
<pass-through-router>
<file:outbound-endpoint path="./out" outputPattern="pop-[DATE].txt"/>
</pass-through-router>
</outbound>
</service>
</model>
</mule>
意思是将我邮箱里的信读入 然后通过component进行业务处理 最后用file进行输出 简单的很
下面看看com.muleinaction.Test吧 也是超级简单:
package com.muleinaction;
import org.mule.util.Base64;
public class Test {
public String test(javax.mail.internet.MimeBodyPart m){
try {
return m.getFileName()+" "+m.getContent()+" "+m.getEncoding();
} catch (Exception e) {
return "error";
}
}
}
这样运行后就可以进行邮件收取了