[SOLVED] Python script sending email notifications to only one user
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Python script sending email notifications to only one user
Hello --
We are using an ticket tracking application called Roundup, and part of its installation includes a python script that sends out e-mail reminders to users of open tickets. The script is meant to be run as a cron job.
The script is supposed to send reminders to multiple users, but is able to send to only one user. I asked about this issue, and the following reply was sent to me:
Quote:
I think that your original problem of only getting the last email has to do with the script indentation (in Python very i
important).
Here some things to look at:
- At line 56 you have a for loop in it "address" variable is being assigned on line 61
- that for loop ends at line 140
- the loop starting on line 101 and line 141 lock to me pretty much the same
So my "guess fix" without digging deeper is:
- comment lines 140 to 159
- indent lines 162 to 166 by one level, so that they are within the first for loop.
I went through the motions of implementing the suggestions, with the files in question change to the following:
Quote:
140 # old_priority = None
141 # for priority_order, activity_date, creation_date, issue_id in l:
142 # priority = db.issue.get(issue_id,'priority')
143 # if (priority != old_priority):
144 # old_priority = priority
145 # print >>body, '<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name')
146 # creation = (creation_date - date.Date('.')).pretty()
147 # if creation is None:
148 # creation = (creation_date - date.Date('.')).pretty()
149 # title = db.issue.get(issue_id, 'title')
150 # issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
151 # issue_id, issue_id)
152 # activity = (activity_date - date.Date('.')).pretty()
153 # print >>body, '''<tr><td>%s</td><td>%s</td><td>%s</td>
154 # <td>%s</td></tr>'''%(creation, issue_id, activity, title)
155 # print >>body, '</table>'
156 #
157 # print >>body, '''<p>To view or respond to any of the issues listed
158 # above, simply click on the issue ID. Do <b>not</b> respond to
159 # this message.</p>'''
160 #
161 # finish of the multipart
162 writer.lastpart()
163
164 # all done, send!
165 smtp = SMTPConnection(db.config)
166 smtp.sendmail(db.config.ADMIN_EMAIL, address, message.getvalue())
NOTE: It does not show it in this posting, but lines 162, 165, and 166 are indented by one tab.
When the script is run using the following command syntax:
File "/root/roundup-reminder.py", line 162
writer.lastpart()
^
IndentationError: unexpected indent
I have included the script with this posting, and I wanted to know what changes do I need to make in order for the script to be able to send to multiple users.
The error is not from the file you sent, as far as I can see: I have no problems running the script. However, nor is anything commented out, so you must have sent the old version. Also, you haven't put the whitespace in the code you posted in [CODE][/CODE] tags - it is impossible for us to help you with your indentation if we can't see it! And you've missed the relevant 'line before' which shows us what the indentation level was before the block. So, to summarise: easiest thing to do is to attach the modified script to your post, or to post more of the script correctly indented.
Apologies if this comes across as a rant of sorts - it is honestly not meant to be so, but we really can't help you very much with the information you gave us
I spoke with a colleague about the script, and there was a problem with the indentation. My apologies for the posting not showing the script in its original form. Basically, the loop in question was not indented to the proper location, and the commands within it being seen as not part of the loop. Once the correction was made,
the script worked without issue. The corrected version of the script has been uploaded as an attachment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.