Hi All,
could you help me to find "how to attach file without upload file in DAM and direct attach to email and send ".
Solved! Go to Solution.
Views
Replies
Total Likes
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
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
Single file working fine but I have added multiple files and added for loop it moves infinity loop can you help me
I have not tried multiple files. I'll give it a try and let you know how it goes.
multifile upload working only file name issue like that I have upload 4 file and received in the mail 9 files (request Parameter + upload files) and every file name same
Views
Likes
Replies