Oracle – How to Call Unix Sendmail

linuxoracleunix

I know that is possible to send mails using the oracle-db by UTL_SMTP, and there are several examples of such usage everywhere.

My question is: Can I call the GNU/Unix/Linux Sendmail to perform a similar action?

Best Answer

Why do you want to use sendmail? Is it just because it is simpler than UTL_SMTP? You should really look into UTL_MAIL.

See this: http://www.orafaq.com/wiki/Send_mail_from_PL/SQL

To send mail from an Oracle db, you might:

  • Use UTL_TCP, way too low-level, old school, not recommended.
  • Call Unix Sendmail (external program) using DBMS Scheduler. Kind of complex -- you need to setup credentials to run OS processes. Anyone who has tried this knows it's not trivial. Technically possible, but why put yourself through the pain. I personally wouldn't do this.
  • Use UTL_SMTP, better than UTL_TCP, was the best approach pre-10g.
  • Custom mail proc that you write, which makes use of UTL_SMTP. Okay for 9i, but for 10g+ you'd just be reinventing the wheel, so use UTL_MAIL instead.
  • Use UTL_MAIL, simplest approach on 10g/11g/12c
  • If you are really bent on using sendmail and would be open to an asychronous/batch solution, consider creating a DIRECTORY that Oracle can write text files in MIME format into (via UTL_FILE), then set up a cron job that runs every 5 minutes which processes these files through sendmail and deletes them if successful.