Index: main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt	(revision 7223)
+++ main/waeup.sirp/trunk/src/waeup/sirp/browser/browser.txt	(revision 7225)
@@ -42,14 +42,14 @@
   >>> browser.open('http://localhost/myuniversity')
   >>> browser.getLink('Enquiries').click()
-  >>> browser.getControl('Submit').click()
-  >>> print browser.contents
-  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
-  ...Error: All fields must be filled...
-  ...
-
-  >>> browser.getControl(name='fullname').value = "Bob Tester"
-  >>> browser.getControl(name='email').value = "xx@yy.zz"
-  >>> browser.getControl(name='descr').value = "test message"
-  >>> browser.getControl('Submit').click()
+  >>> browser.getControl('Send').click()
+  >>> print browser.contents
+  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
+  ...There were errors...
+  ...
+
+  >>> browser.getControl(name='form.fullname').value = "Bob Tester"
+  >>> browser.getControl(name='form.email_from').value = "xx@yy.zz"
+  >>> browser.getControl(name='form.body').value = "test message"
+  >>> browser.getControl('Send').click()
   >>> print browser.contents
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
@@ -185,28 +185,15 @@
   ...
 
-We fill in a wrong email address::
-
-  >>> browser.getControl(name='email').value = "xx@yy"
-  >>> browser.getControl(name='descr').value = "test message"
-  >>> browser.getControl('Submit').click()
-  >>> print browser.contents
-  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
-  ...<li class="message">Error: xx@yy is not a valid email address.</li>
-  ...
-
-Now we fill the form properly (this will send a real message to
-contact@waeup.org)::
+We fill the form and try to send message to contact@waeup.org)::
 
   >>> browser.open('http://localhost/myuniversity/contactadmin')
-  >>> browser.getControl(name='email').value = "xx@yy.zz"
-  >>> browser.getControl(name='descr').value = "test message"
-  >>> browser.getControl('Submit').click()
-  >>> print browser.contents
-  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
-  ...<li class="message">Your message has been sent.</li>
-  ...
-
-If this test fails, chances are, that the local machine has no SMTP
-server installed.
+  >>> browser.getControl(name='form.body').value = "test message"
+  >>> browser.getControl('Send').click()
+  >>> print browser.contents
+  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
+  ...<li class="message">You don't have a user account.</li>
+  ...
+
+We can't send messages without a user account.
 
 
Index: main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py	(revision 7223)
+++ main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py	(revision 7225)
@@ -26,6 +26,4 @@
 import time
 import re
-import smtplib
-from email.mime.text import MIMEText
 from zope import schema
 from zope.authentication.interfaces import (
@@ -52,5 +50,5 @@
     ILocalRolesAssignable, DuplicationError, IConfigurationContainer,
     ISessionConfiguration, ISessionConfigurationAdd,
-    IPasswordValidator)
+    IPasswordValidator, IContactForm)
 from waeup.sirp.permissions import get_users_with_local_roles, get_all_roles
 from waeup.sirp.students.catalog import search as searchstudents
@@ -60,5 +58,5 @@
 from waeup.sirp.widgets.restwidget import ReSTDisplayWidget
 from waeup.sirp.authentication import get_principal_role_manager
-from waeup.sirp.utils.helpers import get_user_account
+from waeup.sirp.utils.helpers import get_user_account, send_mail
 
 grok.context(IWAeUPObject)
@@ -454,76 +452,73 @@
 
 #
-# Contact forms...
-#
-class ContactAdminForm(WAeUPPage):
-    grok.context(IUniversity)
+# Contact form...
+#
+
+from megrok.layout import Form
+class ContactAdminForm(Form):
     grok.name('contactadmin')
-    grok.template('contactadminform')
+    #grok.context(IUniversity)
+    #grok.template('contactadminform')
+    grok.require('waeup.Authenticated')
+    pnav = 2
+    form_fields = grok.AutoFields(IContactForm).select('body')
+
+    @property
+    def config(self):
+        return grok.getSite()['configuration']
+
+    def title(self):
+        userid = self.request.principal.id
+        return u'Contact %s' % self.config.name_admin
+
+    def label(self):
+        return self.title()
+
+    @property
+    def get_user_account(self):
+        return get_user_account(self.request)
+
+    @grok.action('Send now')
+    def send(self, *args, **data):
+        useraccount = self.get_user_account
+        if useraccount is None:
+            self.flash("You don't have a user account.")
+            return
+        fullname = useraccount.title
+        email_from = useraccount.email
+        username = useraccount.name
+        body = data['body']
+        email_to = self.config.email_admin
+        subject = self.config.email_subject
+        success = send_mail(fullname,username,self.config.name,
+                  body,email_from,email_to,subject)
+        if success:
+            self.flash('Your message has been sent.')
+        else:
+            self.flash('A smtp server error occurred.')
+        return
+
+class EnquiriesForm(ContactAdminForm):
+    grok.name('enquiries')
     grok.require('waeup.Public')
     pnav = 2
-
-    @property
-    def config(self):
-        return grok.getSite()['configuration']
-
-    def title(self):
-        """Return True if the calling user is authenticated.
-        """
-        userid = self.request.principal.id
-        if userid != 'zope.anybody':
-            tt = u'Contact %s' % self.config.name_admin
+    form_fields = grok.AutoFields(IContactForm).select(
+                          'fullname', 'email_from', 'body')
+
+    @grok.action('Send now')
+    def send(self, *args, **data):
+        email_from = data['email_from']
+        fullname = data['fullname']
+        body = data['body']
+        username = u'None'
+        email_to = self.config.email_admin
+        subject = self.config.email_subject
+        success = send_mail(fullname,username,self.config.name,
+                  body,email_from,email_to,subject)
+        if success:
+            self.flash('Your message has been sent.')
         else:
-            tt = u'Enquiries'
-        return tt
-
-    def label(self):
-        return self.title()
-
-    @property
-    def get_user_account(self):
-        return get_user_account(self.request)
-
-    @property
-    def namefield_label(self):
-        if self.request.principal.title == 'Applicant':
-            return 'Access Code'
-        else:
-            return 'Full Name'
-
-    def update(self, *args, **kw):
-        form = self.request.form
-        if not ('fullname' in form and 'email' in form and 'descr' in form):
-            return
-        self.fullname = fullname = form['fullname']
-        email = form['email']
-        self.descr = descr = form['descr']
-        regno =form['regno']
-        if not (fullname and email and descr):
-            self.flash('Error: All fields must be filled.')
-            return
-        if not re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$",
-                        email):
-            self.flash('Error: %s is not a valid email address.' % email)
-            return
-        if regno == 'zope.anybody':
-            regno = 'Anonymous User'
-        text = """Fullname: %s
-Member ID: %s
-Description: %s
-"""
-        msg = MIMEText(text % (fullname,regno,descr))
-        msg['From'] = '%s <%s>' % (fullname,email)
-        
-        msg['To'] = self.config.email_admin
-        msg['Subject'] = self.config.email_subject
-        server = smtplib.SMTP(self.config.smtp_server)
-        if self.config.smtp_requires_login:
-            server.login(self.config.smtp_username,self.config.smtp_password)
-        server.sendmail(email,self.config.email_admin,msg.as_string())
-
-        server.quit()
-        self.flash('Your message has been sent.')
-        return
-
+            self.flash('A smtp server error occurred.')
+        return
 
 #
Index: main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py	(revision 7223)
+++ main/waeup.sirp/trunk/src/waeup/sirp/browser/viewlets.py	(revision 7225)
@@ -610,9 +610,9 @@
 
     
-class ContactTab(PrimaryNavTab):
+class EnquiriesTab(PrimaryNavTab):
     """Contact tab in primary navigation.
 
-    Display tab only for anonymous. Authenticated users can call the
-    form from the user navigation bar.
+    Display tab only for anonymous. Authenticated users can call a
+    contact form from the user navigation bar.
     """
     grok.order(6)
@@ -622,27 +622,7 @@
     pnav = 2
 
-    # Also zope.manager has role Anonymous.
-    # To avoid displaying this tab, uncomment the following.
-    #def tab_title(self):
-    #    userid = self.request.principal.id
-    #    if userid != 'zope.anybody':
-    #        tt = u''
-    #    else:
-    #        tt = u'Enquiries'
-    #    return tt
-
-    #@property
-    #def active(self):
-    #    view_pnav = getattr(self.view, 'pnav', 0)
-    #    userid = self.request.principal.id
-    #    if view_pnav == self.pnav and userid == 'zope.anybody':
-    #        return 'active'
-    #    return ''
-
     @property
     def link_target(self):
-        return self.view.application_url('contactadmin')        
-
-
+        return self.view.application_url('enquiries')
 
 #
