How to Configure and Send Email from Oracle Database Using UTL_MAIL (Oracle 11g, 12c, 18c, 19c, 21c & 23ai)
How to Configure and Send Email from Oracle Database Using UTL_MAIL (Oracle 11g, 12c, 18c, 19c, 21c & 23ai)
📅 Last Updated: August 2026
This guide has been completely updated for Oracle Database 11g, 12c, 18c, 19c, 21c, and Oracle Database 23ai. It explains how to configure the Oracle UTL_MAIL package, configure the SMTP server, grant the required privileges, configure Network ACLs, send emails from PL/SQL, troubleshoot common errors, and follow Oracle Database security best practices.
Email notifications play an essential role in enterprise Oracle Database environments. Organizations use database-generated emails to notify administrators of backup failures, tablespace alerts, blocking sessions, scheduled job completion, Data Guard status, RMAN results, application events, and business workflow notifications.
Oracle provides the UTL_MAIL package to simplify sending emails directly from PL/SQL programs. Compared to the lower-level UTL_SMTP package, UTL_MAIL offers a much simpler programming interface while still supporting plain text and HTML email messages.
However, simply installing UTL_MAIL is not enough. Modern Oracle Database releases require Network Access Control Lists (ACLs), SMTP configuration, package installation, and appropriate user privileges before email functionality can be used successfully.
This guide explains the complete Oracle email architecture, installation, configuration, security requirements, troubleshooting techniques, and production best practices for sending emails from Oracle Database.
Install the UTL_MAIL package, configure the SMTP_OUT_SERVER initialization parameter, grant EXECUTE permission on UTL_MAIL, configure the required Network ACL permissions for the SMTP server, and test email delivery using the UTL_MAIL.SEND procedure.
What is UTL_MAIL?
UTL_MAIL is an Oracle-supplied PL/SQL package that enables Oracle Database to send email messages through an SMTP server.
It provides a simplified interface for sending emails directly from stored procedures, scheduled jobs, database triggers, monitoring scripts, and enterprise applications.
UTL_MAIL is commonly used for:
- Database monitoring alerts
- RMAN backup notifications
- Oracle Data Guard monitoring
- Scheduled job completion reports
- Application workflow notifications
- Error reporting
- Business process automation
- Security alerts
UTL_MAIL vs UTL_SMTP
| Feature | UTL_MAIL | UTL_SMTP |
|---|---|---|
| Ease of Use | Very Easy | Advanced |
| Programming Complexity | Low | High |
| HTML Email | Supported | Supported |
| Attachments | Limited | Flexible |
| SMTP Command Control | No | Full Control |
| Recommended For | Most Applications | Advanced Email Solutions |
How Oracle Sends Email
PL/SQL Program
│
▼
UTL_MAIL Package
│
▼
SMTP_OUT_SERVER
│
▼
SMTP Mail Server
│
▼
Recipient Mailbox
When a PL/SQL program calls the UTL_MAIL package, Oracle connects to the configured SMTP server, transfers the email message, and the mail server delivers it to the intended recipients.
Business Impact
Database-generated email notifications are widely used in enterprise production environments to improve operational visibility and reduce response time.
Typical production uses include:
- RMAN backup success and failure notifications
- Database startup and shutdown alerts
- Tablespace usage alerts
- ASM disk group monitoring
- Data Guard synchronization monitoring
- Scheduler job notifications
- Security event reporting
- Application workflow emails
- Oracle E-Business Suite notifications
Oracle Email Architecture
Oracle Database
│
▼
PL/SQL
│
▼
UTL_MAIL
│
▼
Network ACL
│
▼
SMTP Server
│
▼
Internet / Corporate Mail
│
▼
Recipient
Network ACLs provide fine-grained security by controlling which database users are permitted to establish network connections to external SMTP servers.
SMTP Overview
SMTP (Simple Mail Transfer Protocol) is the standard protocol used for sending email messages across computer networks.
Oracle Database acts as an SMTP client while the organization's mail server receives and forwards outgoing email.
Common SMTP ports include:
| Port | Purpose |
|---|---|
| 25 | Standard SMTP |
| 465 | SMTP over SSL |
| 587 | SMTP Submission (STARTTLS) |
Many enterprise environments use an internal SMTP relay to securely forward emails generated by Oracle Database.
Understanding Network ACLs
Beginning with Oracle Database 11g, Oracle introduced Network Access Control Lists (ACLs) to enhance database security.
Even if UTL_MAIL is installed and the user has EXECUTE privileges, Oracle will block network access unless the appropriate ACL permissions have been granted for the target SMTP server.
This security mechanism helps prevent unauthorized PL/SQL code from connecting to external network services.
Prerequisites
- Oracle Database 11g or later.
- SYSDBA or DBA privileges for configuration.
- Access to the Oracle Home directory.
- A reachable SMTP server.
- Network connectivity between the database server and the SMTP server.
- Appropriate Network ACL permissions.
- A database user authorized to send emails.
Before You Begin
Before configuring Oracle Database email functionality, collect the following information from your mail administrator:
- SMTP server hostname or IP address
- SMTP port number
- Whether the server accepts unauthenticated relay from the database server
- Firewall rules between the database server and the SMTP server
- Approved sender email addresses
- Corporate email relay requirements
For production systems, avoid sending email directly to public SMTP servers. Instead, use an internal corporate SMTP relay that is approved by your organization's security team. Configure Network ACLs with the minimum required privileges and grant UTL_MAIL access only to trusted database users and applications.
Step 1 – Verify Whether UTL_MAIL Is Installed
Before configuring email functionality, verify whether the UTL_MAIL package is already installed in the database.
SELECT object_name,
status
FROM dba_objects
WHERE object_name = 'UTL_MAIL';
If the package status is VALID, installation has already been completed.
Step 2 – Install the UTL_MAIL Package
If the package is not installed, connect to the database as SYSDBA and execute the Oracle-supplied installation scripts.
sqlplus / as sysdba
Run the installation scripts from the Oracle Home directory.
@?/rdbms/admin/utlmail.sql @?/rdbms/admin/prvtmail.plb
These scripts create the UTL_MAIL package specification and body.
Step 3 – Configure SMTP_OUT_SERVER
Oracle Database must know which SMTP server will be used to deliver outgoing email.
Configure the initialization parameter:
ALTER SYSTEM SET smtp_out_server='mail.company.com' SCOPE=BOTH;
Verify the parameter.
SHOW PARAMETER smtp_out_server
Step 4 – Grant EXECUTE Privilege
Grant permission to the application schema that will send email.
GRANT EXECUTE ON UTL_MAIL TO HR;
Replace HR with your application schema.
Step 5 – Configure Network ACL
Beginning with Oracle Database 11g, network connections are controlled through Access Control Lists (ACLs). Without the appropriate ACL privileges, email delivery will fail even if UTL_MAIL is installed correctly.
The following example grants the user HR permission to connect to the SMTP server mail.company.com on port 25.
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'mail.company.com',
lower_port => 25,
upper_port => 25,
ace => xs$ace_type(
privilege_list => xs$name_list('connect'),
principal_name => 'HR',
principal_type => xs_acl.ptype_db
)
);
END;
/
Use the host name and port appropriate for your environment.
Step 6 – Verify Network Connectivity
Before testing email delivery, confirm that the database server can reach the SMTP server.
From the operating system, execute one of the following commands.
ping mail.company.com
or
telnet mail.company.com 25
A successful connection confirms that the SMTP server is reachable.
Step 7 – Send Your First Email
The following example sends a simple plain-text email.
BEGIN
UTL_MAIL.SEND(
sender => 'oracle@company.com',
recipients => 'dba@company.com',
subject => 'Oracle Database Email Test',
message => 'UTL_MAIL configuration completed successfully.'
);
END;
/
If no errors occur, the email should be delivered successfully.
Step 8 – Send an HTML Email
UTL_MAIL can also send HTML-formatted messages.
BEGIN
UTL_MAIL.SEND(
sender => 'oracle@company.com',
recipients => 'dba@company.com',
subject => 'Database Status',
message => 'Database Running Successfully
',
mime_type => 'text/html; charset=UTF-8'
);
END;
/
Step 9 – Multiple Recipients
Specify multiple recipients as a comma-separated list.
BEGIN
UTL_MAIL.SEND(
sender => 'oracle@company.com',
recipients => 'dba1@company.com,dba2@company.com',
cc => 'manager@company.com',
bcc => 'audit@company.com',
subject => 'Daily Database Report',
message => 'Daily health check completed successfully.'
);
END;
/
Common Oracle Errors
| Error | Possible Cause | Resolution |
|---|---|---|
| ORA-24247 | Network access denied | Configure the required Network ACL. |
| ORA-29278 | SMTP temporary error | Verify SMTP server availability. |
| ORA-29279 | SMTP permanent error | Review SMTP configuration and sender permissions. |
| ORA-06512 | PL/SQL execution error | Review the complete stack trace. |
| ORA-04063 | Invalid package | Reinstall or recompile UTL_MAIL. |
Troubleshooting Checklist
- Verify that UTL_MAIL is installed and VALID.
- Confirm
SMTP_OUT_SERVERis configured correctly. - Grant EXECUTE on UTL_MAIL to the application user.
- Configure the required Network ACL permissions.
- Verify connectivity to the SMTP server.
- Confirm the sender address is accepted by the SMTP relay.
- Review alert logs and trace files if PL/SQL errors occur.
- Test email delivery using a simple message before deploying production code.
Production Case Study
A production Oracle Database server was configured to send RMAN backup notifications using UTL_MAIL. Although the package had been installed and EXECUTE privileges were granted, every email attempt failed with ORA-24247: network access denied by access control list (ACL). Investigation revealed that the application schema lacked permission to connect to the corporate SMTP relay. After the required Network ACL was configured and SMTP connectivity was verified, backup notifications were delivered successfully to the DBA team, enabling proactive monitoring of nightly backup operations.
Oracle Database Security Considerations
Sending email directly from Oracle Database can be extremely useful, but it also introduces security considerations. Only trusted schemas should be granted permission to send email, and network access should be restricted using Oracle Network Access Control Lists (ACLs).
Follow the principle of least privilege by granting only the minimum permissions required for application functionality.
UTL_MAIL Limitations
Although UTL_MAIL is simple to use, it has several limitations that administrators should understand before deploying it in production.
| Feature | UTL_MAIL |
|---|---|
| Simple Email | Supported |
| HTML Email | Supported |
| Multiple Recipients | Supported |
| Attachments | Basic Support |
| SMTP Authentication | Limited |
| TLS / STARTTLS | Not Directly Supported |
| Advanced MIME Handling | Limited |
For environments that require authenticated SMTP, TLS/STARTTLS, or advanced MIME features, consider implementing a solution based on UTL_SMTP or using an approved internal SMTP relay.
Oracle DBA Best Practices
- Use a dedicated internal SMTP relay for Oracle Database email.
- Grant EXECUTE on UTL_MAIL only to trusted schemas.
- Configure Network ACLs with the minimum required permissions.
- Validate SMTP connectivity before deploying applications.
- Use meaningful sender addresses for automated notifications.
- Log email delivery attempts in application tables where appropriate.
- Monitor Scheduler jobs that send email alerts.
- Test email functionality after database upgrades and patching.
- Protect sensitive information—avoid sending passwords or confidential data by email.
- Document SMTP configuration as part of your database build and disaster recovery procedures.
Common Administrator Mistakes
- Installing UTL_MAIL but forgetting to configure
SMTP_OUT_SERVER. - Granting EXECUTE without configuring the required Network ACL.
- Using an incorrect SMTP server or port.
- Assuming the database server has network connectivity to the SMTP server.
- Using sender addresses rejected by the mail relay.
- Ignoring firewall rules between the database server and SMTP host.
- Sending large volumes of email without monitoring relay limits.
- Not validating package status after upgrades.
Frequently Asked Questions (FAQ)
Is UTL_MAIL installed by default?
No. In many Oracle Database installations, UTL_MAIL must be installed manually using the Oracle-supplied scripts before it can be used.
Why do I receive ORA-24247?
This error indicates that the database user does not have the required Network ACL permission to connect to the SMTP server.
Can UTL_MAIL send HTML emails?
Yes. Specify the appropriate MIME type (for example, text/html; charset=UTF-8) when sending the message.
Can UTL_MAIL send attachments?
UTL_MAIL provides basic attachment capabilities. For more advanced email formatting or complex MIME messages, UTL_SMTP offers greater flexibility.
Can Oracle Database send emails through Microsoft 365 or Gmail?
Modern cloud email services often require SMTP authentication and encrypted connections. Many organizations therefore configure an internal SMTP relay that accepts mail from the Oracle Database server and forwards it securely to external mail services.
Related Oracle Database Articles
- Monitor All DDL Statements at Database Level
- ORA-10564, ORA-01110 Recovery Guide
- Automatic Startup and Shutdown of Oracle Database
- Oracle Error Codes Guide
About the Author
Rana Abdul Wahid is an Oracle Database and Oracle E-Business Suite Consultant with more than 15 years of experience in Oracle Database Administration, Oracle E-Business Suite Application DBA, Oracle Cloud Infrastructure (OCI), Oracle RAC, Oracle Data Guard, RMAN Backup & Recovery, Linux/Unix Administration, MySQL, Microsoft SQL Server, PostgreSQL, and enterprise infrastructure management.
His areas of expertise include Oracle Database Security, Performance Tuning, Backup & Recovery, Oracle E-Business Suite administration, PL/SQL development, Linux system administration, Oracle Cloud Infrastructure (OCI), and enterprise production support.
Conclusion
The Oracle UTL_MAIL package provides a straightforward and reliable method for sending email directly from PL/SQL. By correctly installing the package, configuring the SMTP_OUT_SERVER parameter, granting the required privileges, and implementing Network ACLs, database administrators can automate alerts, reporting, and operational notifications across enterprise environments.
Following the security recommendations and best practices outlined in this guide will help ensure dependable email delivery, simplify database administration, and improve operational visibility while maintaining compliance with Oracle Database security standards.
For production environments, configure a trusted internal SMTP relay, restrict network access using Oracle Network ACLs, regularly validate email functionality after database patching or upgrades, and audit all schemas that are permitted to send email. Combining secure configuration with routine monitoring ensures reliable and maintainable email notification services from Oracle Database.
Found this guide helpful? Explore more Oracle Database, PL/SQL, RMAN, Oracle E-Business Suite, Linux administration, and production troubleshooting articles in the Oracle Error Codes Guide.
Comments
Post a Comment