## Script (Python) "mail2student"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=co_name=None,co_email=None,student_email=None,probtype=None,commt=None
##title=
##
# $Id: mail2admin.py 869 2006-11-15 13:46:49Z henrik $

mhost = context.MailHost
prop = context.portal_properties

# the message format, %s will be filled in from data

message = """
From: %s <%s>
To: %s
Cc: %s
Bcc: %s
Reply-To: %s
Subject: %s
%s
"""

#prop.email_from_address should be used for To:
REQUEST = context.REQUEST
url_tuple = REQUEST.HTTP_REFERER.split('?')
if len(url_tuple) == 2:
    url_tuple[1] ='portal_status_message=Your message has been sent!'
else:
    url_tuple.append('portal_status_message=Your message has been sent!')
redirect_url = "?".join(url_tuple)
REQUEST.set('rurl', redirect_url) # to see the result in the error log
msg = message % (
     co_name,
     co_email,
     student_email,  
     co_email,
     'henrik@waeup.org',
#    'js@aixtraware.de',
     co_email,
     probtype,
     commt,
     )
mhost.send(msg)

REQUEST = context.REQUEST
RESPONSE = REQUEST.RESPONSE

RESPONSE.redirect(redirect_url)
