i think the sendemail.py should be in models
*models/SendEmail.py: *
# -*- coding: utf-8 -*- 
# try something like 
from gluon.tools import Mail 
def send_email(): 
  mail = Mail() 
  #mail.settings.server = 'smtp.hitachiconsulting.com' 
  mail.settings.server = 'smtp.gmail.com:587' 
  mail.settings.sender = '[email protected]' 
  mail.settings.login = '[email protected]:123' 
  x = mail.send( 
  to = ['[email protected]'], subject = 'hello', 
  reply_to = '[email protected]', 
  message = 'Hello ! How are you?' 
  ) 
  if x: 
    nm="Sent Successfully"; 
  else: 
    nm="failed"; 

not sure what do you mean with to schedule sending emails 1 to 15 days and 
16 to 30 days, if you want to send email which is date is 1-15, i think you 
can use conditional if :
if request.now.day >= 1 and request.now.day <= 15:

best regards,
stifan

On Tuesday, August 16, 2016 at 6:26:33 PM UTC+7, madhu nomula wrote:
>
> Thanks Dave. 
>
> I wrote code like below: But I am not sure how to schedule this. Could 
> you please guide me to configure this Scheduler (need bit more 
> elaborated steps). Thank you appreciate your help: 
> ______________________ 
> In Controller: SendEmail.py: 
> # -*- coding: utf-8 -*- 
> # try something like 
> from gluon.tools import Mail 
> def send_email(): 
>     mail = Mail() 
>     #mail.settings.server = 'smtp.hitachiconsulting.com' 
>     mail.settings.server = 'smtp.gmail.com:587' 
>     mail.settings.sender = '[email protected] <javascript:>' 
>     mail.settings.login = '[email protected]:123' 
>     x = mail.send( 
>    to = ['[email protected] <javascript:>'], subject = 'hello', 
>    reply_to = '[email protected] <javascript:>', 
>    message = 'Hello ! How are you?' 
>     ) 
>     if x: 
>         nm="Sent Successfully"; 
>     else: 
>         nm="failed"; 
> _____________ 
> In Controller: scheduler.py 
> from gluon.scheduler import Scheduler 
> # schedule recurring tasks: 
> def sched_tasks(arg1=""): 
>   # arg1 keeps this from being expose as a web page 
>   # instantiate Scheduler class 
>     scheduler = Scheduler(db) 
>     task = scheduler.queue_task("send_email", period = 86400, repeats=1) 
>   # show on console, or add to log 
>     print task 
>     db.commit() 
>
> def stop_tasks(arg1=""): 
>   # arg1 keeps this from being expose as a web page 
>   # instantiate Scheduler class 
>     scheduler = Scheduler(db) 
>     task = scheduler.task_status(db.scheduler_task.task_name == 
> 'send_email') 
>     if hasattr(task, "status") and task.status in ["QUEUED", "RUNNING"]: 
>         stop = scehduler.stop_task(task.uuid) 
>      # show on console or add to log 
>         print cue 
>         db.commit() 
> _____________________________ 
>
>
> Please suggest me, next what I have to do , to schedule sending emails 
> 1 to 15 days and 16 to 30 days . 
>
> Regards, 
> MC 
>
>
> On Wed, Aug 3, 2016 at 12:28 AM, Dave S <[email protected] <javascript:>> 
> wrote: 
> > 
> > 
> > On Tuesday, August 2, 2016 at 10:51:36 AM UTC-7, madhu nomula wrote: 
> >> 
> >> Hi All, 
> >> 
> >> I need help on below requirement. 
> >> 
> >> We have implemented Time sheet  logging tool for users in web2py tool. 
> >> 
> >> Now the requirement is to send email notifications to the users of 
> tool, 
> >> to enter time sheet and submit. 
> >> This email has to be sent for all users from 1 to 15 days of month and 
> 16 
> >> to 30 days of month till the user submits time sheets. 
> > 
> > 
> > I am not sure what you mean here ... That twice a month you start 
> nagging 
> > the users?  That's the easiest interpretation.  Also, I think, easy to 
> do 
> > ... see below. 
> > 
> >> 
> >> 
> >> Please suggest, how can I schedule this sending emails option in Web2Py 
> >> tool. 
> > 
> > 
> > I recommend using the built-in scheduler.  This looks something like: 
> > (read about it at 
> > <URL:
> http://web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler>) 
> > (and note that this is untested, but based on my own scheduler usage and 
> > comments in this forum by Niphlod) 
> > 
> > in your model file (scheduler.py is a good name) 
> > # define scheduler task 
> >    def send_nags(first_reminder = False): 
> >       if first_reminder or now.date in [1, 16]: 
> >         db(db.staff.ALL).update(curts_recd = False) 
> >       mail = auth.settings.mailer 
> >       query = db.staff.curts_recd == False 
> >       rows = db(query) 
> >       for row in rows: 
> >         msg = compose_reminder(row.id, ...) 
> >         mail.send(to=row.email, reply_to="payroll@mybiz", message = msg) 
> > 
> > # instantiate Scheduler class 
> > from gluon.scheduler.import Scheduler 
> > scheduler = Scheduler(db) 
> > 
> > 
> > In one of your controller files: 
> > # schedule recurring tasks: 
> > def sched_tasks(arg1=""): 
> >   # arg1 keeps this from being expose as a web page 
> >   # instantiate Scheduler class 
> >   from gluon.scheduler.import Scheduler 
> >   scheduler = Scheduler(db) 
> >   task = scheduler.queue_task("send_nags", period = 86400, repeats=1) 
> >   # show on console, or add to log 
> >   print task 
> >   db.commit() 
> > 
> > # also add as needed 
> > def stop_tasks(arg1=""): 
> >   # arg1 keeps this from being expose as a web page 
> >   # instantiate Scheduler class 
> >   from gluon.scheduler.import Scheduler 
> >   scheduler = Scheduler(db) 
> >   task = scheduler.task_status(db.scheduler_task.task_name == 
> 'send_nags') 
> >   if hasattr(task, "status") and task.status in ["QUEUED", "RUNNING"]: 
> >      stop = scehduler.stop_task(task.uuid) 
> >      # show on console or add to log 
> >      print cue 
> >      db.commit() 
> > 
> > 
> > 
> > 
> > Use  these from the command line like this: 
> > web2py.py -M -S uploader/default/sched_tasks 
> > or 
> > web2py.py -M -S uploader/default/stop_tasks 
> > 
> > (and of course, you've used the -K option earlier to start the scheduler 
> ... 
> > you can add this to the startup sequence for your webserver) 
> > 
> >  See 
> >    <URL:https://groups.google.com/d/msg/web2py/9WrqIxi75JY/UHxICIC-BQAJ> 
>
> > for more details. 
> > 
> > 
> > -- 
> > Resources: 
> > - http://web2py.com 
> > - http://web2py.com/book (Documentation) 
> > - http://github.com/web2py/web2py (Source code) 
> > - https://code.google.com/p/web2py/issues/list (Report Issues) 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "web2py-users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to