dadaturk
dadaturk

Reputation: 39

How can I do the control that email is delivered?

I'm trying to send an email with python, but how do I find out if the email has been delivered ?

My code for sending e-mail:

import smtplib

server = smtplib.SMTP_SSL("smtp.gmail.com",465)

server.login("[email protected]","pass")

server.sendmail("[email protected]","[email protected]","message")

server.quit()

I'm trying to get a output like this :

if the mail has been sent: OK

if the mail could not be delivered: BAD

Upvotes: 2

Views: 605

Answers (1)

Peter Badida
Peter Badida

Reputation: 12189

TL;DR: If you want notifications, use a service that guarantees them. (ref).

Even though the newest RFC 2821 can enforce (on paper) not to drop an email, as mentioned in the comments you generally won't know when the recipient's mail-server receives the message. The only status you get back is that your SMTP server sent the message, but it could have been dropped later on in the process due to a faulty machine or just a spam filter.

There are bounce messages and various other hacks to combat it such as:

  • remote resources (images, iframes, etc) which if your mail client is at least a little bit secure will prevent such HTTP calls

    this is also where the web-based clients by default fail unless they also cut such resources from the messages and display only after you acknowledge its usage per message basis. Otherwise it'll be just a link or HTML element which will be interpreted solely by your browser (and maybe blocked by an addon) hence going through and calling home with HTTP/S request or even sending a form with data.

  • Outlook's (and other clients') feature of confirming the reading of the message - which can be ignored/canceled

Emails aren't really safe nor there is any guarantee if it'll even get to the other side except that you use a more robust mail server that has been proven to work over the years which might increase the chances of delivery slightly. Nevertheless any action to let you know that the other side got the message depends solely on the recipient's will/security/stupidity to pass through from the machine.

I bet there's (or at least should be) some better, internal, handling of the mail messages within the same domain ([email protected] -> [email protected]) which might have a higher chance of delivery + a proper bounce message, but you never know and nobody will give you an SLA or anything similar either due to the nature of emails.

Same applies even if you'd try to use an attachment doing the same calling home operation - can be prevented by antivirus, firewall, just being in a private network without (public) Internet access, downloading mails with POP3 (and reading offline), etc.

Upvotes: 1

Related Questions