Hi,
I am trying to read ldap data. My ldap has fields such as userid, employeeid, and email. I would like to build a dictionary with the employeeid and email.
I have tried a bunch of thing to no avail. Can someone please help?
Below is some sample code I have been testing. Maybe someone can point me in the right direction. Don't know if any of this is useful.
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from plone import api
# This script will send email to several recipients
# each written down to its own email field
# whose id starts with "email-"
from plone import api
class sendFaculty:
def sendFacultymail(self):
test="nothing"
#email='FacultyEmail@york.cuny.edu'
#membership = context.portal_membership.getMemberInfo()
#username = membership['username']
#emplid = context.acl_users.getUserById(username).getProperty('employeeID')
#membership = context.portal_membership.getMemberInfo()
curemplid='123456789'
#employeeid = membership['employeeID']
#email = context.acl_users.getUserById(curemplid).getProperty('email')
#email = api.user.get(employeeID='curemplid')
#mt = getToolByName(self.context, 'portal_membership')
#member = mt.getMemberByemployeeID(curemplid)
#email=member.getEmail()
#build a dictionary with employeeid and email
mydict={}
count=0
items = list(context.portal_catalog.queryCatalog({"portal_type":("Faculty","Staff"),"path":"/yc1/portal_college/","sort_on" : "getFirst_name" }))
mylist=[]
mylist.append("test")
try:
for b in items:
obj=b.getObject()
objid=obj.keys()
mylist.append(objid)
email=obj.getProperty('email')
#emailf=obj.getField('email').getAccessor(obj)()
#emplid=obj.getProperty('employeeID')
#mydict[emplid]=email
#mylist.append(email)
#membership = obj.getMemberInfo()
#membership = context.portal_membership.getMemberInfo()
membership=context.portal_membership.getMemberById(objid)
mylist.append(membership)
#username = membership['username']
count=count+1
#emplid = context.acl_users.getUserById(username).getProperty('employeeID')
#mylist.append(emplid)
except Exception,e:
pass
mylist.append(str(count))
#this only gives me 3 people
#acl_users = getToolByName(context, 'acl_users')
#groups_tool = getToolByName(context, 'portal_groups')
#groups_tool = getToolByName(context, 'Staff') - this does not work
#groups = acl_users.source_groups.getGroupIds()
#for group_id in groups:
# group = groups_tool.getGroupById(group_id)
# if group is None:
# continue
# members = group.getGroupMembers()
# for m in members:
# member_emails = [m.getProperty('email') for m in members]
#this does not work, even though it should according to documentation
#for member in context.portal_membership.listMembers():
# emplid = member.getProperty('employeeID')
# email=member.getProperty('email')
# mydict[emplid]=email
# test= mydict[emplid]
# count=count+1
# this returns a list of groups
#for d in context.acl_users.searchPrincipals():
# m=d
# count=count+1
semail='kmarjit@york.cuny.edu'
variable="my test variable"
#mailhost = getToolByName(ploneformgen, 'MailHost')
mailhost = getToolByName(self,'MailHost')
subject = "Huuhaa"
# Custom message with a name filled in
message="test"
#message = u"""Hello,
#Thanks for participating %s !
#Cheers,
#http://www.opensourcehacker.com
#""" % (variable)
#source = "info@opensourcehacker.com"
try:
#all_recipients=["kmarjit@york.cuny.edu"]
all_recipients=[semail]
mfrom="kmarjit@york.cuny.edu"
#mailhost.secureSend(message, "kmarjit@york.cuny.edu", source, subject=subject, subtype='plain', charset="utf-8", debug=False, From=source)
mailhost.send(message, all_recipients, "kmarjit@york.cuny.edu", immediate=True)
#return str(count)+str(email)+str(emplid)+str(userid)
return mylist
except Exception,e:
return str(e)
s=sendFaculty()
msg=s.sendFacultymail()
return msg