通过html表单上传文件,并将其作为附件发送到mulesoft的电子邮件

时间:2015-11-03 11:19:21

标签: mule

我使用html表单选择要在电子邮件中作为附件添加的文件。

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 个答案:

答案 0 :(得分:1)

我几乎没有修改过您的代码,它对我有用。

HTML代码

if (c.words == 0) {
          $ammount = 0 + $("input[name='mood[]']:checked").length;
            $price.html($ammount);
        }
        if (c.words <= 80) {
          $ammount = 10 + $("input[name='mood[]']:checked").length;
            $price.html($ammount);
        }
        if (c.words > 80 && c.words <= 200) {
        $ammount = 15 + $("input[name='mood[]']:checked").length;
            $price.html($ammount);
        }
        if (c.words > 300 && c.words <= 400) {
          $ammount = 20 + $("input[name='mood[]']:checked").length;
            $price.html($ammount);
        }

骡子流

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