java - Velocity engine unable to find resource -


Users in my application can get email templates. I am using the velocity engine to send emails in the email template WEB-INF / email_tempaltes /...// >> directory.

This is my code:

  string body = velcityanguage. Merge TemplateInstring (wellcetygen, template ocation, "UTF-8", model);  

Where templateLocation is string variable which looks like this:

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

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -