RenderMailMessage obsolete method replacement on trunk

18 views
Skip to first unread message

rjlopes

unread,
Feb 5, 2009, 4:27:38 PM2/5/09
to Castle Project Users
Hi,

I recently switched to the trunk version and i noticed that the
RenderMailMessage changed and was marked as obsolete, so I tried to
change to some of the overaloaded versions but i didn't know what to
pass as the "parameters" param?

I tried an empty IDictionary or null but got errors. I'm using
nvelocity view engine.

Thanks.

Driscol...@gmail.com

unread,
Feb 5, 2009, 5:28:59 PM2/5/09
to Castle Project Users
If you want to use the overload method with this signature:
RenderMailMessage(string templateName, string layoutName, IDictionary
parameters),

you could do something like this as far as I know , ( note you will
need to create your own template ):

Hashtable emailDictionary = new Hashtable();
emailDictionary.Add("username", "david");
emailDictionary.Add("to", "da...@gmail.com");
emailDictionary.Add("from", "ad...@gmail.com");
emailDictionary.Add("subject", "Test Email");
emailDictionary.Add("message", "This is a test email");
Castle.Components.Common.EmailSender.Message message =
RenderMailMessage("/mail/email.vm", null, emailDictionary);

DeliverEmail(message);

Ricardo Lopes

unread,
Feb 5, 2009, 6:06:01 PM2/5/09
to castle-pro...@googlegroups.com
That's more or less what i was doing, so now you have to pass the variables on the parameters param?

From what you said I noticed the following changes from the RC3:

- The mail folder was default for the view, now do I have to specify that folder?

- From your example i guess you are passing the variables as the parameters params, in RC3 the PropertyBag, Flash, etc was available to the view engine, did this changed?

Thanks.

Driscol...@gmail.com

unread,
Feb 5, 2009, 7:24:13 PM2/5/09
to Castle Project Users
My situation was identical to your situation, I went from RC3 to the
trunk, and I ran into
issues sending emails. I am using nvelocity view engine. As far as I
know, you can definitely use, PropertyBag or Flash
since I believe they are both IDictionaries.

On Feb 5, 6:06 pm, Ricardo Lopes <rjlo...@gmail.com> wrote:
> That's more or less what i was doing, so now you have to pass the variables
> on the parameters param?
>
> From what you said I noticed the following changes from the RC3:
>
> - The mail folder was default for the view, now do I have to specify that
> folder?
>
> - From your example i guess you are passing the variables as the parameters
> params, in RC3 the PropertyBag, Flash, etc was available to the view engine,
> did this changed?
>
> Thanks.
>
> 2009/2/5 <Driscoll.Dav...@gmail.com>

Ricardo Lopes

unread,
Feb 6, 2009, 5:02:36 AM2/6/09
to castle-pro...@googlegroups.com
I was only able to "almost" make it work as I wanted using complete path for the view, complete path including extension for the layout and passing the PropertyBag as parameters param. In my case is like this:

RenderMailMessage("/mail/register", "/layouts/mail.vm", PropertyBag);

And I think something like this would be more appropriate:

RenderMailMessage("register", "mail");

I don't understand why is it so different from the RC3 and from the controller/view mechanism. If I am in a controller and i call RenderView I don't have to include the view folder because is assumed that is the controler name, and nowhere else I include the view extension, and the PropertyBag and Helpers where automaticaly available.

Why is this behaviour so different?
How can i make the Helpers available to the view engine?

Thanks.




--

Ricardo Lopes

Ken Egozi

unread,
Feb 6, 2009, 7:38:41 AM2/6/09
to castle-pro...@googlegroups.com
RenderMailMessage("register", "mail", PropertyBag) should work, I think.

I'll try to delve into this during the weekend.

Patrick Steele

unread,
Feb 6, 2009, 8:05:59 AM2/6/09
to castle-pro...@googlegroups.com
I just looked at some of my code using an early Dec/2008 version of
MonoRail and my mail code is:

System.Collections.Hashtable data = new System.Collections.Hashtable();
data.Add("data1", data1);
data.Add("data2", data2);
Message msg = RenderMailMessage("reminder", null, data);

The "reminder.vm" sits in my "Views\mail" folder.

Hope this helps.

--
Patrick Steele
http://weblogs.asp.net/psteele

Ken Egozi

unread,
Feb 6, 2009, 8:12:01 AM2/6/09
to castle-pro...@googlegroups.com
and
   System.Collections.Hashtable data = new System.Collections.Hashtable();
   data.Add("data1", data1);
   data.Add("data2", data2);

can be conveniently replaced by
   var data = DictHelper
     .CreateO("data1", data1")
     .O("data2", data2);

Ricardo Lopes

unread,
Feb 6, 2009, 8:21:00 AM2/6/09
to castle-pro...@googlegroups.com
In my case didn't work it couldn't find the view if i didn't told it that was on the mail folder and it didn't find the layout unless it specified the layouts folder.

My build number is somewhere between 1000 and 1010.

2009/2/6 Ken Egozi <ego...@gmail.com>



--

Ricardo Lopes

Ricardo Lopes

unread,
Feb 6, 2009, 8:22:16 AM2/6/09
to castle-pro...@googlegroups.com
Also as i wanted to be able to use the Helpers and other stuff i make it work by calling it like this:

System.Collections.IDictionary parameters = new System.Collections.Hashtable();
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters, this.Helpers);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters, this.Flash);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters, this.PropertyBag);
RenderMailMessage("/mail/register", "/layouts/mail.vm", parameters);



2009/2/6 Ricardo Lopes <rjl...@gmail.com>



--

Ricardo Lopes

Ken Egozi

unread,
Feb 6, 2009, 10:49:48 AM2/6/09
to castle-pro...@googlegroups.com
Can you please look at the assembly version of your Castle.Monorail.Framework.dll ?
can be seen on Windows Explorer (say by right-click/properties/Details)
the number should be 1.X.Y.Z
when Z is the subversion revision it was built from

Ricardo Lopes

unread,
Feb 6, 2009, 11:31:53 AM2/6/09
to castle-pro...@googlegroups.com
1.0.3.5510

2009/2/6 Ken Egozi <ego...@gmail.com>



--

Ricardo Lopes

eyal

unread,
Feb 23, 2009, 8:53:40 PM2/23/09
to Castle Project Users
Hi All,

I recently upgraded my app's trunk and encounter the same problem
using RenderMailMessage. I attempted to use the suggested solutions
but non worked.

I used this method:
Message msg = RenderMailMessage("contactus", null, PropertyBag);
msg.To = "mysite.com";
msg.From = email;
msg.Subject = "Contact Us Message";

DeliverEmail(msg);

I keep on getting the following errors:
StackTrace:
at Castle.MonoRail.Framework.Controller.DeliverEmail(Message message)
in c:\svn20\MonoRail\Castle.MonoRail.Framework\Controller.cs:line 1466
at SpecialsNearby.Controllers.ContactController.sendEmail(String
message, String email, String name) in C:\SN3.0\SN\Controllers
\ContactController.cs:line 69
at SN.Controllers.ContactController.SendContact(Contact
contactFromPage) in C:\SN3.0\SN\Controllers\ContactController.cs:line
39

I also ued this method:
Hashtable emailDictionary = new Hashtable();
emailDictionary.Add("to", "mysite.com");
emailDictionary.Add("from", email.Trim());
emailDictionary.Add("subject", "my subject");
emailDictionary.Add("message", "some message");
Message msg = RenderMailMessage("contactus", null,
emailDictionary);
DeliverEmail(msg);

Message: Object reference not set to an instance of an object.

StackTrack:
at
Castle.Components.Common.EmailSender.Smtp.SmtpSender.CreateMailMessage
(Message message) in c:\svn20\Components\EmailSender
\Castle.Components.Common.EmailSender\Smtp\SmtpSender.cs:line 175
at Castle.Components.Common.EmailSender.Smtp.SmtpSender.Send
(Message message) in c:\svn20\Components\EmailSender
\Castle.Components.Common.EmailSender\Smtp\SmtpSender.cs:line 149
at Castle.MonoRail.Framework.Services.MonoRailSmtpSender.Send
(Message message) in c:\svn20\MonoRail\Castle.MonoRail.Framework
\Services\MonoRailSmtpSender.cs:line 80
at Castle.MonoRail.Framework.Controller.DeliverEmail(Message
message) in c:\svn20\MonoRail\Castle.MonoRail.Framework
\Controller.cs:line 1457

Any suggestions? Did anyone resolve this problem?

Thanks

Eyal

On Feb 6, 5:05 am, Patrick Steele <patrick.ste...@gmail.com> wrote:
> I just looked at some of my code using an early Dec/2008 version of
> MonoRail and my mail code is:
>
> System.Collections.Hashtable data = new System.Collections.Hashtable();
> data.Add("data1", data1);
> data.Add("data2", data2);
> Message msg =RenderMailMessage("reminder", null, data);
>
> The "reminder.vm" sits in my "Views\mail" folder.
>
> Hope this helps.
>
> --
> Patrick Steelehttp://weblogs.asp.net/psteele
>
>
>
> On Fri, Feb 6, 2009 at 5:02 AM, Ricardo Lopes <rjlo...@gmail.com> wrote:
> > I was only able to "almost" make it work as I wanted using complete path for
> > the view, complete path including extension for the layout and passing the
> > PropertyBag as parameters param. In my case is like this:
> >RenderMailMessage("/mail/register", "/layouts/mail.vm", PropertyBag);
> > And I think something like this would be more appropriate:
> >RenderMailMessage("register", "mail");
> > I don't understand why is it so different from the RC3 and from the
> > controller/view mechanism. If I am in a controller and i call RenderView I
> > don't have to include the view folder because is assumed that is the
> > controler name, and nowhere else I include the view extension, and the
> > PropertyBag and Helpers where automaticaly available.
> > Why is this behaviour so different?
> > How can i make the Helpers available to the view engine?- Hide quoted text -
>
> - Show quoted text -

Ricardo Lopes

unread,
Feb 24, 2009, 4:13:16 PM2/24/09
to castle-pro...@googlegroups.com
Hi,

As I said on one of my previous messages i was able to workaround the
issue to fit my needs at the moment, but i didn't understood why did
it change so much since the RC3 and i am waiting for more
documentation on this.

This are the changes i noticed:

- i have to especify the absolute path to the view (the mail folder is
not default as it was on RC3)
- i have to especify the absolute path to the layout (the layout
folder is not assumed, dont know how it was on RC3 because i didn't
use layouts on mails, probably wasn't there because i dont remember
them)
- nothing is available as variables on the view engine (nvelocity in
my case) unless i pass it as params, currently i'm passing the
Helpers, Flash and PropertyBag, but Session and Context should be also
there)

Here is the code i'm using:

System.Collections.IDictionary parameters = new System.Collections.Hashtable();
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters,
this.Helpers);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters,
this.Flash);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions(parameters,
this.PropertyBag);
RenderMailMessage("/mail/register", "/layouts/mail.vm", parameters);

I think it should behave in the same way using this:

RenderMailMessage("register", "mail.vm");

But it doesn't, the default folders are not assumed and the default
variables are not available.

I think i should fill a bug, i will investigate a little bit more on
this when i have the time.

Thanks,
Ricardo Lopes.

2009/2/24 eyal <ebar...@gmail.com>:
--

Ricardo Lopes

eyal

unread,
Feb 25, 2009, 1:10:57 AM2/25/09
to Castle Project Users
Thanks for the reply Ricardo

The example you have still does not work for me. It crushes on
DeliverMail()

thanks
eyal

here is the stacktrace:
at Castle.MonoRail.Framework.Controller.DeliverEmail(Message
message) in c:\svn20\MonoRail\Castle.MonoRail.Framework
\Controller.cs:line 1466
at SN.Controllers.ContactController.sendEmail(String message,
String email, String name) in C:\SN3.0\SN\Controllers
\ContactController.cs:line 73
at SN.Controllers.ContactController.SendContact(Contact
contactFromPage) in C:\SN3.0\SN\Controllers\ContactController.cs:line
39

here is my exact code:
System.Collections.IDictionary parameters = new
System.Collections.Hashtable();
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions
(parameters,
this.Helpers);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions
(parameters,
this.Flash);
Castle.MonoRail.Framework.Internal.CommonUtils.MergeOptions
(parameters,
this.PropertyBag);
Message msg = RenderMailMessage("/mail/contactus", "/
layouts/empty.vm", parameters);

//Message msg = RenderMailMessage("contactus", null,
PropertyBag);
msg.To = "in...@mysite.com";
msg.From = email;
msg.Subject = "Contact Us Message";
DeliverEmail(msg);

RenderView("messagesent");
> 2009/2/24 eyal <ebarda...@gmail.com>:

Ricardo Lopes

unread,
Feb 25, 2009, 4:27:27 AM2/25/09
to castle-pro...@googlegroups.com
If the problem is on DeliverMail then is not the same problem.

Did you configure the EmailSender correctly ?

2009/2/25 eyal <ebar...@gmail.com>



--

Ricardo Lopes
Message has been deleted

eyal

unread,
Feb 25, 2009, 8:32:17 PM2/25/09
to Castle Project Users
Ok resolved problem all i had to do was replace smtp.hostname with
mail.hostname in my config file

thanks for the direction Ricardo

Eyal

On Feb 25, 1:27 am, Ricardo Lopes <rjlo...@gmail.com> wrote:
> If the problem is on DeliverMail then is not the same problem.
> Did you configure the EmailSender correctly ?
>
> 2009/2/25 eyal <ebarda...@gmail.com>
> >            msg.To = "i...@mysite.com";
Reply all
Reply to author
Forward
0 new messages