我正在学习 AEM,并且正在满足一个要求,其中我能够发送电子邮件,但无法添加从我的计算机浏览的附件。
要求 -
有一个用 HTML 制作的表单,可以从其中收集信息,并且有一个浏览按钮,可以从其中上传文件。
文件上传后,应立即将包含表单内容和附件的电子邮件发送到电子邮件地址。
同时,通过 POST 请求,表单内容和附件应发送到 JSON
通过电子邮件将内容发送给收件人和 POST 方法工作正常。
关于如何让附件发挥作用有什么建议吗?
Thanks!
在 HTML 中,您可以从类型为“file”的输入框中获取文件::
<form id="submitForm" action="/bin/servlets/submitForm" method="POST" novalidate="novalidate" enctype="multipart/form-data">
<label for="name">Name </label><input name="userName" type="text" class="fieldInner" id="name" required>
<input name="file" value="Choose File" type="file" class="chooseFileInner" required/>
<input type="submit" id="applied" value="Submit"/>
</form>
在java中,您可以将此文件获取为::
RequestParameter attach = request.getRequestParameter("file");
InputStream ip = attach.getInputStream();
MailTemplate mailTemplate = MailTemplate.create(templatePath, session);
HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(new HashMap<String, String>(parameters)), HtmlEmail.class);
ByteArrayDataSource fileDS = new ByteArrayDataSource(ip, "application/pdf");
email.attach(fileDS, "application/pdf", "This is your attached file.");
messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
messageGateway.send(email);
你也可以参考这个在 aem 中通过电子邮件发送图像的链接 http://www.tothenew.com/blog/send-email-and-attach-filesimages-from-aem/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)