I want to use the Scheduler for sending emails.
Everything works fine, but I cannot use an Attachment:
I use json.dumps for the "var" field of scheduler_task, but json.dumps
cannot convert an Attachment.
Next try: pickle.dumps "hides" the attachment and json.dumps accepts this:
db.scheduler_task.insert(
status='QUEUED',
application_name='secure',
task_name='task_name',
function_name='send_email',
args='[]',
vars=json.dumps(dict(to=to, subject=subject, message=str(message),
attachments=pickle.dumps(attachments), cc=cc, bcc=bcc,
reply_to=reply_to,
encoding=encoding, headers=headers)),
enabled=True,
start_time=start_time,
stop_time=start_time+timedelta(days=1),
repeats=1,
retry_failed=retry_failed,
period=period,
timeout=120,
)
Now the scheduler_run reports an error
Traceback (most recent call last):
File "D:\web2py\gluon\scheduler.py", line 217, in executor
vars = loads(task.vars, object_hook=_decode_dict)
File "D:\web2py\gluon\contrib\simplejson\__init__.py", line 403, in loads
return cls(encoding=encoding, **kw).decode(s)
File "D:\web2py\gluon\contrib\simplejson\decoder.py", line 403, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\web2py\gluon\contrib\simplejson\decoder.py", line 421, in
raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
My question: is there a way to queue emails with attachments using the
Scheduler?
Regards, Martin
--