Hello Shawn,

thanks for your reply. I'm using Jetspeed 1.6, so unfortunatly I can't use that. By the way, where do you set the content-type to "text/html"?

I'm currently using the VelocityEmail class as follows:

VelocityEmail vemail = *new* VelocityEmail();
context.put("bestellung", oData); // here I put the oData-object into the context of the user, so that I can use it and read the data from the database
context.put("email", vemail);
vemail.setTo("SvenRichter", "emailaddress");
vemail.setFrom("Recipient", "emailadress");
vemail.setSubject("Bestellung");
vemail.setContext(context);
vemail.setTemplate("portlets/html/email-confirm.vm");
vemail.send();

And it works just fine for text-messages. But I just can't set the content-type to "text/html". As a result the email-client is displaying the message as text, instead of html. That's why I tried the following using the VelocityHtmlEmail class:

VelocityHtmlEmail vemail = new VelocityHtmlEmail(data);
context.put("vmail", vemail);
context.put("bestellung", oData);
vemail.addTo("emailaddress", "Sven Richter"); //data.getUser().getEmail());
vemail.setFrom("Recipient", "emailaddress");
vemail.setHtmlTemplate("portlets/html/email-productpurcase.vm");
vemail.send();

But that way I can't use 'vemail.setContext(context);'. Because of that I can't access the data from the database using '$bestellung' in the template, which makes the whole thing useless to me.

Any idea?

Thanks a lot,
Sven.

sgtmcd schrieb:


I am using spring context to create the engine, I am suspect that is where your issues are....hopefully not.....or maybe you are using spring as well?

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> <property name="resourceLoaderPath"><value>/pages/velocity/</value></property>
        </bean>

//engine is injected by spring context.

HashMap model = new HashMap();
Model.put("some", "stuff");
VelocityContext data = new VelocityContext(model);
StringWriter canvas = new StringWriter(); velocityEngine.mergeTemplate("template.vm", data, canvas); String body = canvas.toString();

if you aren't using spring.......

hopefully you can extract what you need from that.  :-)



Sven Richter wrote:

Thanks for your reply. That's exactly what I was trying to do for the last 2 days. Could you please give me a code sample?

Thanks a lot,
Sven.

sgtmcd schrieb:

I took a different approach. I rendered a velocity template (using the velocity engine) then used standard java mail api stuff, set the body of the email as the rendered velocity template, set the mime type to html, etc.

Shawn

Sven Richter wrote:

Hello,

Can someone please tell me a way to generate a HTML-confirmation email from a velocity template using VelocityEmail or another class?

I know that there's a class VelocityHtmlEmail, but in that class I can't seem to pass the Context from the Java class to the template (there is no 'setContext()' in that class). Or maybe somebody can suggest me another class, that I could use (with a small example on how to use it).

Thanks a lot,
Sven.





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to