Not really sure what you're saying, but I assume that basically you
want to email the company with due date that matches current date.
Wouldn't this work?

currentdate = datetime.date.today()
for row in db(db.company.due_date==currentdate).select():
    mail.send(to=[row.cowner_id],
                subject='Sending the mail by using Cron job'
                message=row.details)

Why are you appending the company details to the list? If you want to
get all of the company's details and email that to everyone, you will
need to email once the loop's done retrieving all the details and
emails.

co_details = []
co_emails = []
for row in db(db.company.due_date==currentdate).select():
    co_emails.append(row.cowner_id)
    co_details.append(row.details)

msg = ' '.join(co_details)
for co_email in co_emails:
    # you could just do to=co_emails if you don't need to send
individual emails
    mail.send(to=[co_email],
                   subject='Sending the mail by using Cron job'
                   message=msg)


On Mar 6, 11:17 pm, Sanjeet Kumar <[email protected]> wrote:
> Actually i have the one company table :-
>
> db.define_table(('comany'),
>                      Field('cowner_id'),
>                      Field('details'),
>                      Field('due_date','date'))
>
> here i want to send the mail with the details by using the cron when the
> date will match to the due date :-
>
> i have the following code in my modules send.py :-
>
> from gluon.tools import Mail
> mail=Mail()
> #specify server
> mail=auth.settings.mailer
> mail.settings.server='smtp.gmail.com:587'
> mail.settings.login='[email protected]:password'
> #specify address to send as
> mail.settings.sender='[email protected]'
> #send the message
> try:
>      import datetime
>      list[]
>      currentdate = datetime.date.today()
>      for row in db(db.company.due_date == currentdate).select():
>           list.append(details)
>      mail.send(to=[row.cowner_id],
>     subject='Sending the mail by using Cron job',
>     message=str(list))
> except Exception, e:
> print 'oops: %s' % e
>
> here the problem is the if the i have many companies in our database than
> how i sent the different mail to each of the different companies at a time
> with all details when the due_date will match to the each of the companies.
> here the for loop scope is ended so that is the reason to it is sending and
> taking the only last data from my database and if i sent the mail by using
> inside the scope of the for loop than the for each of the rows mail will be
> sent with the details so its frustrated that is the reason i want to sent
> the only one mail with all the details to the companies with date which
> matches the today's date. But if the more than one companies in our
> database than it is taking only the last because scope of for loop is ended
> so how i resolve these issues please help me.

Reply via email to