Oracle All-in-One (All you need in only one slide)
OAiO1 - How to send mail with attach using Oracle plsql
The goal is to have in a single image all the objects involved
in a common need of a Data Warehouse in Oracle environment.
Unraveling Multimodality with Large Language Models.pdf
Oracle All-in-One - how to send mail with attach using oracle pl/sql
1. Oracle All-in-OneOracle All-in-One
(All you need in only one slide)(All you need in only one slide)
OAiO1 - How to send mail with attachOAiO1 - How to send mail with attach
using Oracle pl/sqlusing Oracle pl/sql
2. The goal is to have in a single image all the objects involvedThe goal is to have in a single image all the objects involved
in a common need of a Data Warehouse in Oracle environment.in a common need of a Data Warehouse in Oracle environment.
In this slide you can :In this slide you can :
see how to access or configure these objectssee how to access or configure these objects
reproduce the solution with a simple copy and pastereproduce the solution with a simple copy and paste
leaves the reader with the security considerationsleaves the reader with the security considerations
leave to the reader the theoretical insightsleave to the reader the theoretical insights
Any feedback to make it more complete solution is acceptableAny feedback to make it more complete solution is acceptable
3. XML DB Technology
Email package
(UTL_MAIL)
ACL view entries
(DBA_NETWORK_ACLS)
ACL privileges view
(DBA_NETWORK_ACL_PRIVILEGES)
Oracle Parameters
1 – Check XML DB Installation
sqlplus / as sysdba
describe resource_view;
Name Null? Type
------- -------- ----------------------------
RES SYS.XMLTYPE(XMLSchema "http:
//xmlns.oracle.com/xdb/XDBRe
source.xsd" Element "Resourc
e")
select * from all_users where username='XDB';
(It must return 1 row. Both conditions
must be true)
1a – Install XML DB
See Install Documentation
2 – Check existance
sqlplus / as sysdba
select object_name,owner,object_type,status
from dba_objects
where object_name = 'UTL_MAIL';
2a - Create user (eventually)
Grant connect,resource,dba
to &&1 identified by &&2;
2b – Install packages
@&&5rdbmsadminutlmail.sql
@&&5rdbmsadminprvtmail.plb
grant execute on utl_mail to &&1;
4 – Check setting
SQLPLUS / AS SYSDBA
sho parameters smtp_out_server;
(It must be setted to &&4)
4a– Set the parameter
alter system set smtp_out_server='&&4' scope=both;
Substitutions
&&1 = Oracle User that send the email
&&2 = Oracle User password
&&3 = An ACL name of your choice
(e.g. utl_mail.xml)
&&4 = Email Server (e.g. acme.ita.com)
&&5 = Oracle Home path
&&6 = Email receiver (e.g .
massimo_cenci@yahoo.it)
Send email procedure
(p_email)
call
send
5a – Create ACL entry
5b – Assign ACL network
sqlplus / as sysdba
begin
dbms_network_acl_admin.create_acl (
acl => '&&3',
description => 'Allow mail to be send',
principal => '&&1',
is_grant => TRUE,
privilege => 'connect');
commit;
end;
/
begin
dbms_network_acl_admin.assign_acl(
acl => '&&3',
host => '&&4');
commit;
end;
/
5 – Find values
sqlplus / as sysdba
select * from dba_network_acls;
6 – Find values
sqlplus / as sysdba
select * from dba_network_acl_privileges;
(exists also user_network_acl_privileges)
6b – Delete ACL privilege
sqlplus / as sysdba
begin
dbms_network_acl_admin.delete_privilege(
acl => '&&3',
principal => '&&1');
commit;
end;
/
5d – Deassign ACL network
5c – DeleteACL entry
sqlplus / as sysdba
begin
dbms_network_acl_admin.unassign_acl(
host => '&&4');
commit;
end;
/
begin
dbms_network_acl_admin.drop_acl(
acl => '&&3');
commit;
end;
/
7 – Create procedure
sqlplus &&1/&&2
create or replace procedure p_email(
p_sender varchar2
,p_recipients varchar2
,p_subject varchar2
,p_message varchar2
,p_dir varchar2 default null
,p_file varchar2 default null) is
v_fh utl_file.file_type;
v_rfile raw(32767);
v_flen number;
v_bsize number;
v_ex boolean;
begin
if (p_dir is null) then
utl_mail.send(
sender => p_sender
,recipients => p_recipients
,subject => p_subject
,message => p_message
);
else
utl_file.fgetattr(p_dir, p_file, v_ex, v_flen, v_bsize);
v_fh := utl_file.fopen(p_dir, p_file, 'r');
utl_file.get_raw(v_fh,v_rfile, v_flen);
utl_file.fclose(v_fh);
utl_mail.send_attach_raw(
sender => p_sender
,recipients => p_recipients
,subject => p_subject
,message => p_message
,attachment => v_rfile
,att_inline => FALSE
,att_filename => p_file
);
end if;
end;
/
8 – Run procedure
sqlplus &&1/&&2
exec p_email('Dba','&&6','OAiO1_Test','Hello world', 'DATA_PUMP_DIR', 'dp.log');
OAiO1 - How to send mail with attach using Oracle pl/sql
Oracle All-in-One
(All you need in only one slide)
6a – Add ACL privilege
sqlplus / as sysdba
begin
dbms_network_acl_admin.add_privilege (
acl => '&&3',
principal => '&&1',
is_grant => TRUE,
privilege => 'resolve'
);
commit;
end;
/
(This privilege if you need host
IP resolution)
DATA_PUMP_DIR
dp.log
3 – Access to directory
sqlplus / as sysdba
grant read,write on directory DATA_PUMP_DIR to
&&1;
(It is an example: the directory and the file dp.log
are always present after installation)
send_attach_raw
Oracle All-in-One By Massimo Cenci