Difference between UTL_MAIL and UTL_SMTP in PL/SQL

As a developer, you might have encountered a situation where client needed error or warning messages after certain programs are executed. Monitoring program continuously will be obviously waste of hours for them. So they demand automatic mails to be delivered to them whenever programs goes in error or warning. This requirement can be fulfilled in PL/SQL using UTL_MAIL and UTL_SMTP packages. SMTP (Simple Mail Transfer Protocol) is used by both to transmit mails over the network.

To help you in deciding which one to use, below are the differences between UTL_MAIL and UTL_SMTP

Introduced in Oracle 10g and thereafterIntroduced in Oracle 8i and thereafter
Easier to use as compared to UTL_SMTPOlder version and require some knowledge of SMTP
Requires parameter SMTP_OUT_SERVER to get initialized in init.ora fileDoes not require any initialization parameter
Does not require SMTP connection to be opened explicitlyRequires SMTP connection to be opened explicitly inside the package

UTL_SMTP.OPEN_CONNECTION(host => 'smtp.google.com', port => 465);
Message priority can be definedMessage priority cannot be defined
Host and Port are not required to be passed in codeHost and Port are required to be passed in code
You can define MIME Type of attachment. Default is 'text/plain; charset=us-ascii' MIME Type cannot be defined
Does not requires explicit handshakeRequires handshake with SMTP server


Best between UTL_MAIL and UTL_SMTP

UTL_MAIL and UTL_SMTP both are good except UTL_MAIL is much simpler to configure than UTL_SMTP. You can check your Oracle database version in which your application is running. Choice should be definitely UTL_MAIL if your database version is 10g and above.

To err is human, so if I have missed any points, please mention them in comments. I will incorporate it in this difference table. If you liked this post then drop comments of appreciation.

Put your comments below if you liked this post. Your feedback and suggestions are valuable to us.

Did you enjoy this post? Then subscribe here and help me to deliver oracle technology related articles in more interesting way.


One thought on “Difference between UTL_MAIL and UTL_SMTP in PL/SQL

  1. It seems UTL_SMTP will not work for recipients , CC and BCC if they are comma separated values.But in the case of UTL_MAIL, all the three works for Csvs?

Leave a Reply

Your email address will not be published. Required fields are marked *