[Zope] Python Scrip
Chy Ty
chyty at hipt.com.vn
Mon Nov 3 23:00:23 EST 2003
I want to write a python script to send an email to my staff. but it appear
an erro
Script line 14
contentObject = review_state.object
^
SyntaxError: invalid syntax
what was wrong?
My script like this
contentObject = review_state.object
def isIn(list1, list2):
y=0
for x in list1:
if x in list2:
y += 1
return y
mailList=[]
for item in context.portal_membership.listMembers():
memberId = item.id
# Remember that a real name is not mandatory, so fall back to the
username
if item.fullname:
memberName = item.fullname
else:
memberName = memberId
memberInterests = item.interest
# ...and another that's the keywords of this object
contentKeywords = contentObject.subject
# Check to see if there's a match between the two
isInterestedIn = isIn(memberInterests, contentKeywords)
# This is the key condition:
# If the user has the Member role and
# we have an email address and
# the user's interested in this content and
# we have permission to email them
if 'Member' in
context.portal_membership.getMemberById(memberId).getRoles() \
and (item.email !='') and isInterestedIn and item.emailPermission:
# add them to the list of people we're emailing
mailList.append(item.email)
# check that we can send email via the Zope standard Mail Host
try:
mailhost=getattr(context, context.portal_url.superValues('Mail
Host')[0].id)
except:
raise AttributeError, "Cannot find a Mail Host object"
# Let's write an email:
mMsg = 'Dear ' + memberName + ',\n\n'
mMsg += 'We thought you\'d be interested in hearing about:\n'
mMsg += contentObject.TitleOrId() + '\n\n'
mMsg += 'Description: \n' + contentObject.Description() + '\n\n'
mMsg += 'More info at:\n' + contentObject.absolute_url() + '\n'
mTo = item.email
mFrom = 'you at yoursite.com'
mSubj = 'New Content available'
# and send it
mailhost.send(mMsg, mTo, mFrom, mSubj)
recipients = string.join(mailList, sep='\n')
keywordsString = string.join(contentKeywords, sep='\n')
mTo = 'you at yourdomain.com'
mMsg = 'The following people were sent a link to\n'
mMsg += contentObject.absolute_url() + '\n\n'
mMsg += recipients + '\n\n'
mMsg += 'The keywords were:\n' + keywordsString
mSubj = 'Content announcement email confirmation'
mailhost.send(mMsg, mTo, mFrom, mSubj)
More information about the Zope
mailing list