0% found this document useful (0 votes)
36 views2 pages

For Package Installation

This document provides instructions for installing and configuring the Oracle email procedure, including running scripts to set it up, setting the SMTP server, and examples of using the procedure to send a basic email and an email with an attachment. The example attachment procedure demonstrates opening a file, reading it line by line into a variable, and attaching that variable content to an email sent using the UTL_MAIL package.

Uploaded by

mnadeemali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

For Package Installation

This document provides instructions for installing and configuring the Oracle email procedure, including running scripts to set it up, setting the SMTP server, and examples of using the procedure to send a basic email and an email with an attachment. The example attachment procedure demonstrates opening a file, reading it line by line into a variable, and attaching that variable content to an email sent using the UTL_MAIL package.

Uploaded by

mnadeemali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

For Package Installation

connect / as sysdba

@$ORACLE_HOME/rdbms/admin/utlmail.sql
@$ORACLE_HOME/rdbms/admin/prvtmail.plb

Email Procedure only for mail

ALTER SYSTEM SET smtp_out_server = 'mailserver.domain.com'; --IP Address or Domain Name


DECLARE
vSender VARCHAR2(30) := '[email protected]'; --Address Send From
vRecip VARCHAR2(30) := '[email protected]';
vSubj VARCHAR2(50) := 'Enter the subject here';
vMesg VARCHAR2(4000) := 'Enter the body';
vMType VARCHAR2(30) := 'text/plain; charset=us-ascii';
BEGIN
utl_mail.send
(vSender, vRecip, NULL, NULL, vSubj, vMesg, vMType, NULL);
END;
/
Email with attachment

CREATE OR REPLACE PROCEDURE p_send_email_with_attach (


DIRECTORY IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
MESSAGE IN VARCHAR2
)
IS
file_handle UTL_FILE.file_type;
output VARCHAR2 (4000);
attachment_text VARCHAR2 (4000);
add_date VARCHAR2 (20)
:= TO_CHAR (SYSDATE, 'ddmmrr' || '_' || 'hh24:mi:ss');
v_dir VARCHAR2 (30) := DIRECTORY;
v_recipients VARCHAR2 (200) := recipients;
v_sub VARCHAR2 (30) := subject;
v_message VARCHAR2 (2000) := MESSAGE;
BEGIN
file_handle :=
UTL_FILE.fopen (LOCATION => v_dir,
filename => 'file_to_attach.txt',
open_mode => 'R'
);

LOOP
BEGIN
UTL_FILE.get_line (file_handle, output);
-- we read the file, line by line
attachment_text := attachment_text || UTL_TCP.crlf;
--and store every line in the attachment_text variable, separated by a ?new line? character.
EXCEPTION
WHEN OTHERS
THEN
EXIT;
END;
END LOOP;

UTL_FILE.fclose (file_handle);
UTL_MAIL.send_attach_varchar2 (sender => '[email protected]',
recipients => v_recipients,
subject => v_sub,
MESSAGE => v_message,
attachment => attachment_text
);
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (-20001, 'Error: ' || SQLERRM);
END;

You might also like