Problem with mailqueue in a cronscript

I have configured my Mailhost to send all Mails asynchron via Queue. If i start a cronscript via an extra client no mail is sended if the Parameter is immediate=False (thats required to send via mailqueue). If it set to True, all works.

If is use the same code snippet in a BrowserView all is fine and the mail is going out. Have anyone an Idea? Perhaps, is the threading the problem, if the instance goes down in the end?

# -*- coding: utf-8 -*-
"""
Command-line script to be run from a ZEO client:
bin/cron-client run cron.py
"""
from zope.component.hooks import setSite
from plone import api

# get the Site Object from the Root Node of ZMI
# here: Mountpoint mysite / PloneInstance plone

site = app.unrestrictedTraverse("mysite/plone")

# Sets the current site as the active site
setSite(site)
with api.env.adopt_user(username="webadmin"):
    api.portal.send_email(
        recipient="john.doe@test.local",
        subject="subject test",
        body="body test",
        immediate=False)

Perhaps you are missing an:

import transaction; transaction commit()

No that is not the reason, i have checked this.

Given you have a browser view you could also thy to supply a ~/.netrc file like this:

machine 127.0.0.1
login webadmin
password password

and try to change the cronjob to:

curl -ns 127.0.0.1:8080/Plone/@@my-view

That should work as well

Thanks, i will do this as another option.

What i see:the messages are avaiable in the "tmp/" Mailqueue Directory. Hmm.

1 Like