Ajeeb.K.P
Ajeeb.K.P

Reputation: 1053

Django detect errors while sending mail

def send_one_mail(request):
   send_mail('The subject', 'The body to testing', '[email protected]',['[email protected]'],    fail_silently=False)
   return HttpResponse("This mail has sent successfull")

And my settings.py is

EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.example.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'

I have a view (which works) as shown above, here [email protected] is sender and [email protected] is the receiver.

How can i check and act according to errors in sending mail? (I want to show "Some error occured" in such errors)

How can i determine if the [email protected](reciver) exists or not? (if email can't be reached, i want to show the user that the email doesn't exist)

I am using postfix,dovecot etc. in server.

Upvotes: 0

Views: 1036

Answers (2)

Ajeeb.K.P
Ajeeb.K.P

Reputation: 1053

django-mail-queue

Anyway, i finally ended-up with using the below package.

pip install django-mail-queue

And here is the docs

https://django-mail-queue.readthedocs.org/en/latest/

Upvotes: 0

Odif Yltsaeb
Odif Yltsaeb

Reputation: 5656

You can pick up some errors when you use fail_silently = False. Just wrap send_mail in try/except.

When i wanted more control over e-mail sending, then i stopped using django mailing completely and installed lamson instead (lamsonproject.org). You can basically create your own mail server with it, attach your django orm to it and provide detailed feedback about what has happened to your e-mails. If you insert some kind of downloadable content into those e-mails (like images), then you can even give hashes to images and verify this way if e-mail has been opened too. You could do that with django based email sending too. Lamson just gives bit more control over the what and how that goes on after you hit send button.

Upvotes: 1

Related Questions