Code to Send E-Mails from an Oracle Stored Procedure

Code to Send E-Mails from an Oracle Stored Procedure

The following code (based on the UTL_SMTP package supplied in Oracle8i V8.1.6, release 2) enables you to receive e-mails from the database, reporting a correct ending backup, a corrupted backup, a database fail, or any message related to database admin.

First Step: Install the necessary Java classes
_____________

The typical installation automatically installs them, but if you chose a custom installation perform the following commands:

 Connect as SYS User. 		Run %ORACLE_HOME/javavm/
plsql/jlib/initjvm.sql Run %ORACLE_HOME/rdbms/
java/install/initplsj.sql

Second Step: Write the PL/SQL code
______________

Write the following PL/SQL Code:

 CREATE OR REPLACE PROCEDURE send_mail		(  sender     IN VARCHAR2,		   recipient  IN VARCHAR2,		   subject    IN VARCHAR2,		   message    IN VARCHAR2)		IS		  mailhost     VARCHAR2(30) := 
'YOUR.SMTP.SERVER'; mail_conn utl_smtp.connection; crlf VARCHAR2( 2 ):= CHR( 13 )
|| CHR( 10 ); mesg VARCHAR2( 1000 ); BEGIN mail_conn := utl_smtp.open_connection
(mailhost, 25); mesg:= 'Date: ' || TO_CHAR( SYSDATE,
'dd Mon yy hh24:mi:ss' ) || crlf || 'From: <'||sender||'>' || crlf || 'Subject: '||subject || crlf || 'To: '||recipient || crlf || '' || crlf || message; utl_smtp.helo(mail_conn, mailhost); utl_smtp.mail(mail_conn, sender); utl_smtp.rcpt(mail_conn, recipient); utl_smtp.data(mail_conn, mesg); utl_smtp.quit(mail_conn); END;

It’s ready to use. Try it from SQLPlus:

 begin send_mail('sender e-mail','dest e-mail','here 
goes subject','here goes message');end;/
Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as