Solved
Email service send mail with file attachments
Hi All,
could you help me to find "how to attach file without upload file in DAM and direct attach to email and send ".
Hi All,
could you help me to find "how to attach file without upload file in DAM and direct attach to email and send ".
Hi @ritesh01
<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>

try {
RequestParameter attach = request.getRequestParameter("file");
InputStream ip = attach.getInputStream();
HtmlEmail email = new HtmlEmail();
//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.");
email.addTo("receiver@example.com");
email.setSubject("test email subject");
email.setMsg("text email body");
email.setHtmlMsg("<html><head></head><body><p>html email body</p></body></html>");
email.setFrom("sender@example.com","TestUser");
// Declare a MessageGateway service
MessageGateway<Email> messageGateway;
messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
messageGateway.send(email);
} catch (EmailException e) {
e.printStackTrace();
}

Thanks
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.