java - Velocity engine unable to find resource -
Users in my application can get email templates. I am using the This is my code: Where velocity engine
to send emails in the email template WEB-INF / email_tempaltes /...// >> directory.
which looks like this:
string body = velcityanguage. Merge TemplateInstring (wellcetygen, template ocation, "UTF-8", model);
templateLocation
is
"/ email_templates /request-feedback.vm "
How do I send mail here:
Send Private Zer e-mail (Last String To Email Address, Last String EEmail Address, Last String Subject, Last String Enclosure Path, Last String Attachment, Last Mail Mail, Last String Template Location) {Properties Property = New Property (); MimeMessagePreparator preparator = New MimeMessagePreparator () {Public Zero Ready (MimeMessage MimeMessage) Exception {MimeMessageHelper Message = New MimeMessageHelper (mimeMessage, true, "UTF-8"); Message.setTo (toEmailAddresses); Message.setFrom (new Internet address (via email address)); Message.setSubject (subject); Maps & lt; String, Object & gt; Model = new hashmop & lt; String, Object & gt; (); Model.put ("phone", mail.text ()); Model.put ("email", mail.getEmail ()); Model.put ("Message", Mail .getMessage ()); String body = VelocityEngineUtils.mergeTemplateIntoString (VelocityEngine, templateLocation, "UTF-8", model); Message.setText (body, true); If (StringUtils.isBlank (Attachment Path)) {FileSystemResource File = New FileSystemResource (Attachment); Message.add Attachment (attachment name, file); }}}; This.mailSender.send (prepared); }
I tested to send email to my local machine and it works fine, but when I installed it on the server, I got an exception:
org Apache.velocity.exception.ResourceNotFoundException: unable to find resource /email_templates/request-feedback.vm '
How can I fix this? Where should I store email templates? thank you in advanced!
----------- Edited: ----------- I have created classes directory and webers - INF and My templates have been added there
And now I get the template like this:
emailSender.sendEmail (mail.getEmail), "info@somemail.com", "Your message was successfully sent", mail, "/ classes / templates / request-st-answer.vm");
and get the same error:
The mail could not be created; Nested exception org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource
me Do not know what MergeTemplateIntoString merge, but another solution is to recover the template from the classpath and format it using MessageFormat.
string result; Last Stringware TemplateData = New Stringwriter (); Last InputStream templateIn = YourClassName.class.getClassLoader () GetResourceAsStream (path); (Int b = templateIn.read (); b! = -1; b = templateIn.read ()) {templateData.write (b); } TemplateIn.close (); Result = message format.format (templatedettraStress (), logic);
Comments
Post a Comment