Emmanuel Blot kirjoitti:
>> Not yet. I'm just looking code in trac.notification but it's not very
>> descriptive. An example would help...
> 
> I agree ;-)
> Sorry, no spare time.

Just for further reference, here is one of the simples approaches I and 
few others from #trac IRC managed to stitch together last night.

For people that asre just reading this: if you want to send e-mail by 
using Trac settings (usernames and such) from some project here is small 
  sample how it can be achieved.

I put contents of those two files in xml-like <code></code> tags.

First you need you email template. We put it simple way:

<code file="notify_email.txt">
You got this e-mail from Trac since you wanted to be notified.
-- 
$project.name <${project.url or abs_href()}>
$project.descr
</code>

And then script code itself:
<code file="send_email.py">
from trac.env import Environment
from trac.notification import NotifyEmail
from trac.core import *
from trac.web.chrome import ITemplateProvider

class SampleNotification(NotifyEmail):

     def __init__(self, env):
         self.template_name = 'notify_email.txt'
         NotifyEmail.__init__(self, env)

     def notify(self, resid, subject):
         subject = '[%s] %s' % (self.config.get('project', 'name'), subject)
         NotifyEmail.notify(self, resid, subject)

     def get_recipients(self, resid):
         return ([self.email_map[resid]], [])

class SampleNotificationComponent(Component):
     implements(ITemplateProvider)

     def get_templates_dirs(self):
         return '.' # This is path to template.

# It's advised to use open_environment here
env = Environment('/path/to/project/', create=0)

# Manually load and enable plugin to get template path.
env.enabled[SampleNotificationComponent] = True

mtn = SampleNotification(env)
mtn.notify('tracuser', 'Notification from script')
</code>

Nothing complex, only downside was that all mechanics needed that 
template. Maybe it could be made a bit more robust so you don't need to 
provide one if you don't want to... But hey, it works.

-- 

Jani Tiainen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to