Re: [Zope] MailHost and Bcc
Catherine E. Reinehr wrote: try: mailhost=getattr(context, context.superValues('Mail Host')[0].id) except: raise AttributeError, cant find a Mail Host object ...passing comment, this is extremely bad code. A bare try/except is bad. Why catch the exception in the first place, just let it propogate. try: mailhost.send(printed, mTo, mFrom, mSubj) request.RESPONSE.redirect('/sbps/application_success') except: request.RESPONSE.redirect('/sbps/application_error') Another bare except, also insanely bad... You could do with looking at either MailTemplates or, better still, Twiddler with a plain text input parser and email output renderer. cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] MailHost and Bcc
Good morning! My web site utilizes forms pretty extensively, and I've been trying to figure out how--on one particular form, an admission application--to bcc all copies to another address. Depending on which campus the applicant chooses, the app is emailed to a different person; the program director wants to receive ALL the apps, without the other recipients knowing. But I just can't seem to make it work. Of course, that might have something to do with the fact that I'm not a programmer, which is why I'm asking for help. Any suggestions would be greatly appreciated! The coding looks like this: # Example code: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE try: mailhost=getattr(context, context.superValues('Mail Host')[0].id) except: raise AttributeError, cant find a Mail Host object contacts = { 'Bay Minette': '[EMAIL PROTECTED]', 'Center Point': '[EMAIL PROTECTED]', 'Pell City': '[EMAIL PROTECTED]', 'Shelby': '[EMAIL PROTECTED]', 'Enterprise': '[EMAIL PROTECTED]', 'Daphne': '[EMAIL PROTECTED]', 'Montgomery': '[EMAIL PROTECTED]' } if request.has_key('campus'): mTo = contacts[request['campus']] else: mTo = 'School of Business and Professional Studies [EMAIL PROTECTED]' mFrom = 'School of Business and Professional Studies [EMAIL PROTECTED]' if request.has_key('email') and request.has_key('first_name') and request.has_key('last_name'): if request['email'] != '' and request['first_name'] != '' and request['last_name'] != '': mFrom = %s %s %s % (request['first_name'], request['last_name'], request['email']) mSubj = 'SBPS Application' print Application Information print - print Term:\t\t, request['term'] print Campus:\t, request['campus'] print Name:\t\t, request['prefix'], request['first_name'], request['middle_name'], request['last_name'] print Preferred Name:\t\t, request['preferred_name'] print Maiden Name:\t\t, request['maiden_name'] print DOB:\t\t%s/%s/%s % (request['dob_month'], request['dob_day'], request['dob_year']) print Address:\t\t, request['address'] if request.has_key('address_2'): if request['address_2'] != '': print \t\t\t, request['address_2'] print City:\t\t, request['city'] print State:\t\t, request['state'] print Zip Code:\t\t, request['zip'] print Email:\t\t, request['email'] print Home Phone:\t, request['phone_home'] print Work Phone:\t, request['phone_work'] print Cell Phone:\t, request['phone_cell'] print if request.has_key('citizenship'): if request['citizenship'] == 'U.S.': print Citizenship:\t\t, request['citizenship'] else: print Citizenship:\t\t, request['citizenship_other'] print Marital Status:\t, request['optional_martial_status'] print Ethnic Origin:\t, request['optional_ethnicity'] print Religion:\t, request['optional_religion'] if request.has_key('work_experience'): print ' Work Experience:\t', request['work_experience'] if request.has_key('financial_aid'): print ' Financial Aid:\t\t', request['financial_aid'] if request.has_key('veteran'): print ' Veteran\'s Benefits:\t', request['veteran'] print print 'Academic Information' print ' High School:\t', request['high_school'] print ' City:\t\t', request['high_school_city'] print ' State:\t\t', request['high_school_state'] print ' Graduated:\t', request['high_school_graduated'] print '' if request.has_key('school_name') and request.has_key('school_city') and request.has_key('school_state') and request.has_key('school_credits'): schools = [school for school in request['school_name'] if school != ''] i = 0 print Other schools attended: print --- for school in schools: print School:\t, school print City:\t, request['school_city'][i] print State:\t, request['school_state'][i] print Credits:\t, request['school_credits'][i] print i = i + 1 print Applicable Military Training: if request.has_key('military_training'): if request['military_training'] != '': print request['military_training'] else: print 'None' print 'Source:' print request['source'] print #print request #return printed try: mailhost.send(printed, mTo, mFrom, mSubj) request.RESPONSE.redirect('/sbps/application_success') except: request.RESPONSE.redirect('/sbps/application_error') #return printed - Catherine E. Reinehr Webmaster Publications Designer Huntingdon College 1500 E. Fairview Ave. Montgomery, AL 36106 (334) 833-4429 / Flowers 207 ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
Re: [Zope] MailHost and Bcc
I doubt that the MailHost supports bcc with the send() function. I for one don't use the MailHost's send() function. I just use it's _send() function for the actual sending and I create the email message manually using the email package in python. But that's a whole different story. If you look up the Secure MailHost product I think it has a function called secureSend() or something which I think has a bcc parameter that you might find useful. Catherine E. Reinehr wrote: Good morning! My web site utilizes forms pretty extensively, and I've been trying to figure out how--on one particular form, an admission application--to bcc all copies to another address. Depending on which campus the applicant chooses, the app is emailed to a different person; the program director wants to receive ALL the apps, without the other recipients knowing. But I just can't seem to make it work. Of course, that might have something to do with the fact that I'm not a programmer, which is why I'm asking for help. Any suggestions would be greatly appreciated! The coding looks like this: # Example code: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE try: mailhost=getattr(context, context.superValues('Mail Host')[0].id) except: raise AttributeError, cant find a Mail Host object contacts = { 'Bay Minette': '[EMAIL PROTECTED]', 'Center Point': '[EMAIL PROTECTED]', 'Pell City': '[EMAIL PROTECTED]', 'Shelby': '[EMAIL PROTECTED]', 'Enterprise': '[EMAIL PROTECTED]', 'Daphne': '[EMAIL PROTECTED]', 'Montgomery': '[EMAIL PROTECTED]' } if request.has_key('campus'): mTo = contacts[request['campus']] else: mTo = 'School of Business and Professional Studies [EMAIL PROTECTED]' mFrom = 'School of Business and Professional Studies [EMAIL PROTECTED]' if request.has_key('email') and request.has_key('first_name') and request.has_key('last_name'): if request['email'] != '' and request['first_name'] != '' and request['last_name'] != '': mFrom = %s %s %s % (request['first_name'], request['last_name'], request['email']) mSubj = 'SBPS Application' print Application Information print - print Term:\t\t, request['term'] print Campus:\t, request['campus'] print Name:\t\t, request['prefix'], request['first_name'], request['middle_name'], request['last_name'] print Preferred Name:\t\t, request['preferred_name'] print Maiden Name:\t\t, request['maiden_name'] print DOB:\t\t%s/%s/%s % (request['dob_month'], request['dob_day'], request['dob_year']) print Address:\t\t, request['address'] if request.has_key('address_2'): if request['address_2'] != '': print \t\t\t, request['address_2'] print City:\t\t, request['city'] print State:\t\t, request['state'] print Zip Code:\t\t, request['zip'] print Email:\t\t, request['email'] print Home Phone:\t, request['phone_home'] print Work Phone:\t, request['phone_work'] print Cell Phone:\t, request['phone_cell'] print if request.has_key('citizenship'): if request['citizenship'] == 'U.S.': print Citizenship:\t\t, request['citizenship'] else: print Citizenship:\t\t, request['citizenship_other'] print Marital Status:\t, request['optional_martial_status'] print Ethnic Origin:\t, request['optional_ethnicity'] print Religion:\t, request['optional_religion'] if request.has_key('work_experience'): print ' Work Experience:\t', request['work_experience'] if request.has_key('financial_aid'): print ' Financial Aid:\t\t', request['financial_aid'] if request.has_key('veteran'): print ' Veteran\'s Benefits:\t', request['veteran'] print print 'Academic Information' print ' High School:\t', request['high_school'] print ' City:\t\t', request['high_school_city'] print ' State:\t\t', request['high_school_state'] print ' Graduated:\t', request['high_school_graduated'] print '' if request.has_key('school_name') and request.has_key('school_city') and request.has_key('school_state') and request.has_key('school_credits'): schools = [school for school in request['school_name'] if school != ''] i = 0 print Other schools attended: print --- for school in schools: print School:\t, school print City:\t, request['school_city'][i] print State:\t, request['school_state'][i] print Credits:\t, request['school_credits'][i] print i = i + 1 print Applicable Military Training: if request.has_key('military_training'): if request['military_training'] != '': print request['military_training'] else: print 'None' print 'Source:' print request['source'] print #print request #return printed try: mailhost.send(printed, mTo, mFrom, mSubj) request.RESPONSE.redirect('/sbps/application_success') except: