aspose file tools*
The moose likes Spring and the fly likes sending mail using velocity template Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "sending mail using velocity template" Watch "sending mail using velocity template" New topic
Author

sending mail using velocity template

Mukhi Vla
Ranch Hand

Joined: Apr 22, 2010
Posts: 50
I am trying to use velocity template to send mail. I am getting the following error when i run the application.

ResourceManager : unable to find resource 'forgot-password.vm' in any resource loader.

I have forgot-password.vm file available in my classpath. I placed this file in the same directory where my controller lives.

my directory structure is : com/company/web/PasswordController.java

com/company/web/forgot-password.vm

i am pointing the .vm template like this from my passwordController class.


Can anyone help me how can solve the error.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't know if that argument expects a file path or a resource name, but either way, you need to fully qualify it.
Mukhi Vla
Ranch Hand

Joined: Apr 22, 2010
Posts: 50
i got rid of that error by defining velocityEngine bean with 'resourceLoaderPath' property value.



But I am facing a different issue now.

I have french translated text in my mail body. I want to send mails in different languages. To support that i have a french translated text in my template.

English text: The account information you requested is below.

French Text:Les informations de compte que vous avez demandé est inférieur à

But in mail i have the above french text coming like this: Les informations de compte que vous avez demandé est inférieur Ã


how can i solve this issue?


Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

What you have there is data, which was encoded using UTF-8, being displayed by something which incorrectly assumes it was encoded in some other charset (probably ISO-8859-1 or Windows-something). So you're going to have to fix some encoding declarations somewhere.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Or multiple places, like the template file encoding itself, and the Velocity template merging, and possibly the email session you're using to send it.
Mukhi Vla
Ranch Hand

Joined: Apr 22, 2010
Posts: 50
Character encoding param is set to 'utf-8' already.



I did check that the problem is not with velocity template. I tried sending message by appending text to StringBuffer. With this change also it is not preseting the characters as it is. Still the message is printed like this "Les informations de compte que vous avez demandé est inférieur à "
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't understand what you mean when you say the message is "printed". Perhaps the problem is with whatever is doing the printing?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And, as I said, the mail session itself needs to be sending in the proper encoding (or maybe just the content encoding header).
Mukhi Vla
Ranch Hand

Joined: Apr 22, 2010
Posts: 50
I don't understand what you mean when you say the message is "printed". Perhaps the problem is with whatever is doing the printing?


I mean mail message containing different characters than what I have.
Mukhi Vla
Ranch Hand

Joined: Apr 22, 2010
Posts: 50
i solved this by placing encoding parameter in mergeTemplateIntoString() method



It works
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending mail using velocity template