django-notifications not sending any email - django

I'm trying to use django-notification and I can't get it to send any emails. The notifications appears in the Notices, but when I do python manage.py emit_notices this is what I get:
acquiring lock...
acquired.
(0.001) SELECT `notification_noticequeuebatch`.`id`, `notification_noticequeuebatch`.`pickled_data` FROM `notification_noticequeuebatch`; args=()
releasing lock...
released.
0 batches, 0 sent
done in 0.00 seconds
This is the code sending the Notice:
admin = User.objects.get(id=1)
notification.send_now([amin], "order_form_created", {"from_user": admin})
Notice settings looks right, my user is subscribed to this kind of notice. From what I understand the app looks in Notification Batches, which are always empty ..
Edit: Looks like the problem was the email server .. I used an external SMTP and it worked.

try notification.queue(..) instead of send_now(..) then python manage.py emit_notices

You are doing send_now() so why the emit_notices management command?

Related

Django post-office setup

Perhaps it is just because I've never set up an e-mail system on Django before, or maybe I'm missing it... but does anyone have any insight on how to properly configure django post-office for sending queued e-mails?
I've got a mailing list of 1500 + people, and am hosting my app on heroku - using the standard email system doesn't work because I need to send customized emails to each user, and to connect to the server one by one leads to a timeout.
I've installed django-post_office via pip install, installed the app in settings.py, I've even been able to get an email to send by going:
mail.send(['recipient'],'sender',subject='test',message='hi there',priority='now')
However, if I try to schedule for 30 seconds from now let's say:
nowtime = datetime.datetime.now()
sendtime = nowtime + datetime.timedelta(seconds=30)
and then
mail.send(['recipient'],'sender',subject='test',message='hi there',scheduled_time=sendtime)
Nothing happens... time passes, and the e-mail is still listed as queued, and I don't receive any emails.
I have a feeling it's because I need to ALSO have Celery / RQ / Cron set up??? But the documentation seems to suggest that it should work out of the box. What am I missing?
Thanks folks
Actually, you can find this in the documentation (at the time I'm writing this comment):
Usage
If you use post_office’s EmailBackend, it will automatically queue emails sent using django’s send_mail in the database.
To actually send them out, run python manage.py send_queued_mail. You can schedule this to run regularly via cron:
* * * * * (/usr/bin/python manage.py send_queued_mail >> send_mail.log 2>&1)

Flask-Mail not sending emails, no error is being reported

All, I'm trying to setup flask-mail to send notifications to my email when a user registers.
I'm getting no error messages from the script used to send the email, but nothing is actually being sent, or at least, nothing is being received.
Is there a log file which can show if an email was sent, rejected, or maybe if there was even a problem logging onto the server? How does on track this problem?
Any ideas here?
Flask-Email use smtplib which can set debug level: https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L139. You can set it with MAIL_DEBUG = True or DEBUG = True. Also check that MAIL_SUPPRESS_SEND = False and TESTING = False.
With debug I can see in stdout mail progress: success, fail, recipients and etc.
See details: http://pythonhosted.org/Flask-Mail/#configuring-flask-mail.
tbicr has the most likely fix, check MAIL_SUPPRESS_SEND first.
What ended up burning me (being new to flask) is that when you instantiate your Mail() object, be sure it's after you've set your app.config values. The Mail() object doesn't go back and look at these values after the fact, so they will default to bad values. What's frustrating is that you won't see any errors when you try to send messages with the default/bad values. At least not as of my posting.
I know this post is from a while ago, but I just ran into the same issue. Like #tbicr mentioned make sure that app.testing is set to False. As it states in the Flask-Maildocs here:
"If the setting TESTING is set to True, emails will be suppressed. Calling send() on your messages will not result in any messages being actually sent."
This was exactly my problem. I implemented Google reCAPTCHA into one of my forms and the app.testing was set to True so I did not have to hit the reCAPTCHA box every time. By removing the app.testing or by setting it to False, the emails were able to be sent.

django-paypal signal update

I've been picking my way though django-paypal documentation and have got a signal connecting when I send a IPN from the sandbox simulator.
I can do:
UserProfile.objects.update(has_paid=True)
I can also do:
UserProfile.objects.update(middle_name=sender.custom) # sender.custom set to "Lyndon" on IPN
and everyone gets a year free. Not what I want...
What I'd like to do is
up = UserProfile.objects.get(user=ipn_obj.custom)
up.has_paid = False
up.save()
but on such occasions I get a server error (500) message on the Instant Payment Notification (IPN)
simulator.
IPN delivery failed. HTTP error code 500: Internal Server Error
I still get a Paypal IPN in my database and it will show up not flagged and with a payment status of "Completed". However, the signal is not connecting.
I'm just not getting something (or multiple things!) here. Any pointers much appreciated.
T
Try to use that,
UserProfile.objects.filter(user=ipn_obj.custom).update(has_paid=False)
For that kind of bugs, which you can not understand what is the problem use ipdb:
you should install ipdb,
$ pip install ipdb
and to run go to your code which doesn't work and add,
import ipdb; ipdb.set_trace()
when you run on your local (I mean with runserver) and make request to make that code pieces run, you will see the trace after the above line.
Note that to go next use "n" and to continue use "c" on ipdb.
It would help if I paid attention...
up = UserProfile.objects.get(user.username=ipn_obj.custom)
user.username...

Django - sending 600 emails with celery -- some are skipped?

I have a Django project that needs to send out around 600 emails. I have Celery set up and it works, for the most part. I have the Django project set up to use my Google Apps (Business version -- ie: paid for) email account as the sending account. For testing purposes, I have every email sent to me -- not to the client.
The issue I am having is that Celery seems to randomly skip people in the list. When I start the process of sending all 600 emails, Celery works away, sending emails (I can see them show up in my inbox) but I only receive a total of about 420 emails. When Celery finishes, there are still 180 or so people that need the email. If I click "send emails" again with ONLY the remaining 180 people, it will finish the job and, at the end of two attempts, will have sent emails to all 600 people.
Why would Celery be skipping people?
Yes, you will get those gmail errors and it's not particularly predictable.
You could just use django-mailer instead -- I do, and deal with those gmail connection errors by letting django-mailer automatically retry the failed sending attempts until they succeed.
Check out this SO question for more folks suggesting you just use django-mailer vs celery for mail.
Advice on Python/Django and message queues

Time Based Reminder Email in Django

I want incorporate a timed based reminder email of the events for the day in django. Basically I have a model which has all the events (including the date of the event). I want to send emails to concerned people at around 8.00 AM in the morning of each day about the events for the day. How do I incorporate this is django?
Thanks
I reckon a custom management command to send the alerts, commanded by django-chronograph should do the trick
I wrote a database-backed email queue, to send out emails from a single django install and not have to worry about SMTP throttling and whatnot. It's dead simple -- one model class for the email with a sendit() method, and a command-line script to flush the queue, which I run with cron.
http://gist.github.com/629663