2015-11-03 65 views
0

与电子邮件附件我使用HTML表单选择一个文件来attcahed作为电子邮件的附件。上传文件和发送它作为mulesoft

HTML表单:

<!DOCTYPE html> 
<html> <head></head> 
<body> 

Email Address: <input type="text" name="address" id="address" 
placeholder="Recipient's email add"/> 
<label for='message' >Write Your Message *:</label><br/> 
<textarea rows="10" cols="50" name='message' id='message'></textarea> 
Enter your Name : <input type="text" name="name" id="name" 
placeholder="Sender's Name"/> 
Sending Email To: <input type="text" name="email" id="email" 
placeholder="Recipient's Name"/> 
Upload your file :<input type="file" name="file" id="file"/> 
<input type="submit" name="Submit" value="Submit" id="submit"/> 
<input type="reset" name="Reset" value="Reset" id="reset"/> 
</form> 
</body> 
</html>` 

在安装变压器我设置该文件。

XML是:

<http:listener-config name="HTTP_Listener_Configuration" host="localhost" 
port="8083" doc:name="HTTP Listener Configuration" > 
</http:listener-config> 

<smtp:gmail-connector name="Gmail" contentType="text/html" validateConnections="true" doc:name="Gmail"/> 

<flow name="parsetemplateforemailFlow"> 
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" 
doc:name="HTTP" /> 
<parse-template location="*...file.html"/> 
</flow> 
<flow name="parsetemplateforemailFlow2"> 
<http:listener config-ref="HTTP_Listener_Configuration" path="/login" 
doc:name="HTTP"/> 
<logger message="#[message]" level="INFO" doc:name="Logger"/> 
<set-attachment attachmentName="file.png" value="#[payload.file]" 
contentType="image/png" doc:name="Attachment"/> 
<set-variable variableName="emailaddress" value="#[payload.address]" 
doc:name="Variable"/> 

<set-variable variableName="senderName" value="#[payload.name]" 
doc:name="Variable"/> 
<set-variable variableName="recipient" value="#[payload.email]" 
doc:name="Variable"/> 
<set-variable variableName="content" value="#[payload.message]" 
doc:name="Variable"/> 
<component class="parsetemplateforemail.Email" doc:name="Java"/> 
<logger message="#[payload]" level="INFO" doc:name="Logger"/> 
<smtp:outbound-endpoint host="smtp.gmail.com" port="587" 
user="*************" password="**********" connector-ref="Gmail" to=" 
#[flowVars.emailaddress]" from="*********" subject="Test Email" 
responseTimeout="10000" doc:name="SMTP"/> 
</flow> 
</mule> 

但我发现了一个空文件作为附件。如何解决这个问题?

回答

1

我几乎没有修改过你的代码,它正在为我工​​作。

HTML代码

<html> <head></head> 
<body> 
<form method="get" action="http://localhost:9091/send"> 
Email Address: <input type="text" name="address" id="address" placeholder="Recipient's email add"/> <br/> 
<label for='Body' >Write Your Message *:</label><br/><br/> 
<textarea rows="10" cols="50" name='body' id='body'></textarea><br/><br/> 
Upload your file :<input type="file" name="file" id="file"/><br/><br/><br/> 
<input type="submit" name="Submit" value="Submit" id="submit"/> 
<input type="reset" name="Reset" value="Reset" id="reset"/> 
</form> 
</body> 
</html> 

骡子流

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" 
xmlns:context="http://www.springframework.org/schema/context" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd"> 
<smtp:gmail-connector name="gmail" contentType="text/html" validateConnections="true" doc:name="Gmail"/> 

<flow name="parsetemplateforemailFlow" doc:name="parsetemplateforemailFlow"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="9091" doc:name="HTTP" path="test"/> 
    <set-property propertyName="Content-Type" value="text/html" doc:name="Property"/> 
    <parse-template location="index.html" doc:name="Parse Template"/> 
</flow> 
<flow name="parsetemplateforemailFlow2" doc:name="parsetemplateforemailFlow2"> 
    <http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="9091" path="send" doc:name="HTTP"/> 
    <set-variable variableName="emailaddress" value="#[message.inboundProperties.'http.query.params'.address]" doc:name="Variable"/> 
    <expression-filter expression="#[flowVars.emailaddress != &quot;&quot;]" doc:name="Expression"/> 
    <logger message="Sending email to :: #[flowVars.emailaddress]" level="INFO" doc:name="Logger"/> 
    <set-attachment attachmentName="file.png" value="#[message.inboundProperties.'http.query.params'.file]" contentType="image/png" doc:name="Attachment"/> 
    <set-payload doc:name="Set Payload" value="#[message.inboundProperties.'http.query.params'.body]"/> 
    <smtp:outbound-endpoint host="smtp.gmail.com" port="587" 
          to="#[flowVars.emailaddress]" 
          from="Sadiq" subject="Test Email" responseTimeout="10000" doc:name="SMTP" connector-ref="gmail" 
          password="Katihar1981" user="sadique.arslan%40gmail.com"/> 

    <logger message="Email sent." level="INFO" doc:name="Logger"/> 
</flow> 
</mule>