Hi Christoph,

this is what I’ve been using in the past. Maybe a bit too complicated, but it 
works without leaking sessions.

        public static void 
fillMailWithContentFromComponentInBackgroundThread(ERMailDeliveryHTML mail, 
String pageName, NSDictionary<String, Object> values) {
                // When running in a regular R/R-loop this is not needed! Just 
use the current context.

                // So, we're running outside of the R/R loop... We need a dummy 
context...
                ERXRequest fakeRequest = new ERXRequest("GET", "", "HTTP/1.1", 
null, null, null);
                ERXWOContext dummyContext = new ERXWOContext(fakeRequest);

                // ...which will implicitly create a session, so prepare it to 
not log session termination in accounting
                PDBUBasicSession dummySession = (PDBUBasicSession) 
dummyContext.session();
                dummySession.setDontLogSessionTermination(true);

                // not sure why this is needed
                dummyContext.setMutableUserInfo(new NSMutableDictionary<String, 
Object>());

                ERXWOContext.setCurrentContext(dummyContext);

                // prepare the page...
                WOComponent contentPage = 
WOApplication.application().pageWithName(pageName, dummyContext);
                if (values != null) {
                        for (String keyPath : values.allKeys()) {
                                
contentPage.takeValueForKeyPath(values.objectForKey(keyPath), keyPath);
                        }
                }

                // ...and add the content of the page to the message 
                mail.setCharset("UTF-8");
                
mail.setHTMLContent(contentPage.generateResponse().contentString());
                mail.setHiddenPlainTextContent("Dies ist eine HTML E-Mail. 
Bitte schalten Sie die Ansicht um.");

                // terminate the dummy session, otherwise we have a session leak
                dummySession.terminate();
        }

HTH,

Timo

> Am 04.10.2015 um 21:07 schrieb CHRISTOPH WICK | i4innovation GmbH, Bonn 
> <[email protected]>:
> 
> Hi List,
> 
> I'd like to send batch emails in a separate thread using ERMailDeliveryHTML 
> and a Component based HTML.
> 
> Unfortunately, I need a WOContext to generate my subclass of WOComponent. Is 
> there a way to generate the WOContext outside the RR-Loop?
> 
> C.U.CW
> --
> What are the three enemies of a programmer? Sunlight, oxygen, and the 
> appalling roar of the birds.
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/th-dev%40onlinehome.de
> 
> This email sent to [email protected]


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to