0

I am writing a program that will be sending external emails using postfix with the mail -s command and I need to verify that the email was sent to the specified address.

In which case, I am curious if postfix right away reports an error that I am able to get as a return code if email failed sending or if postfix will say it was a success as long as a valid email (example@example.com) was entered and then later report in a log file or such that the email was unable to be sent?

Also if the network is down, will postfix still return success as long as a valid email address is used, or will a failure be reported right away?

| improve this question | | | | |
1

If your postfix configuration is set for logs you can check the logs for the status of a message.

It will contain information such as:

Mar 25 16:07:40 serverName postfix/smtp[3113]: B169ZZZ24F: host foo.net.mx1.name.foo.net[1.2.3.4] refused to talk to me: 421 Offline: HELO/FDNS

Mar 25 16:07:40 serverName postfix/smtp[3036]: 7ZZZFC2440: to=<customer@yahoo.com>, relay=mtaz.amz.yahoodns.net[66.196.118.35]:25, delay=11, delays=0.35/0/0.6/9.9, dsn=2.0.0, status=sent (250 ok dirdel)

Mar 25 16:07:36 serverName postfix/smtp[3073]: ZZZZ3C623E: to=<user@customer.com>, relay=none, delay=0.55, delays=0.35/0/0.2/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=customer.com type=A: Host not found)

This info can be retrieved via a script with lines like: (Not my work. Thanks to whom ever, this is used everyday.)

grep 'status=sent' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'

grep 'status=deferred' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'

grep 'status=bounced' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'
| improve this answer | | | | |
  • Whoever wrote your grep|awk|sed|sed pipeline was extremely inexperienced. To start with, you don't need to run sed twice, sed can take multiple -e arguments or you can just separate multiple sed statements in a single sed script with ;. Secondly if you're using awk, you don't need grep as well: awk '/status=bounced/ {print $7}'. Similarly, you don't even need sed either, awk's gsub() or gensub() functions can do regexp search and replace: awk '/status=bounced/ {$7 = gensub(/to=<([^]]*)>,/,"\\1","g",$7); print $7}' /var/log/mail.log. – cas Mar 28 '16 at 23:44
  • The first two things are basic, novice-level sed and awk knowledge, so basic that they can't be ignored when posted in an answer. The third is moderately advanced - although the improved regexp (doing in one regexp what was being done in two regexps with two different sed commands) is only slightly above complete novice regexp usage too. – cas Mar 28 '16 at 23:47
1

Some serious errors (like I/O errors reading the message contents or very badly unparseable messages/addresses) may be reported as failure exits right away, but in general this will not be the case and you cannot count on it.

In case of delivery failure, you should get a bounce (sent back to the user who originated the mail), but even that may be out of Postfix' hands if Postfix successfully forwarded the message to another mail transport agent and the error happened down the line. The bounce could come minutes or days later.

If the network is down, Postfix will still return success. This is a feature, not a bug :-)

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.