I have created a procedure named as send_mail in sql developer oracle which is written below.
create or replace procedure Send_Mail(Msg_To varchar2, Msg_Subject varchar2, Msg_Text varchar2) is
c Utl_Smtp.Connection;
Rc integer;
Msg_From varchar2(50) := 'it.dev23#dawateislami.net'; -- email of my company which hosted on Gmail
Mailhost varchar2(30) := 'smtp.gmail.com';
begin
c := Utl_Smtp.Open_Connection(Mailhost, 587);
Utl_Smtp.Ehlo(c, Mailhost);
Utl_Smtp.StartTLS(c);
Utl_Smtp.Ehlo(c, Mailhost);
Utl_Smtp.Mail(c, Msg_From);
Utl_Smtp.Rcpt(c, Msg_To);
Utl_Smtp.Data(c,
'From: Oracle Database' || Utl_Tcp.Crlf || 'To: ' || Msg_To || Utl_Tcp.Crlf || 'Subject: ' || Msg_Subject || Utl_Tcp.Crlf ||
Msg_Text);
Utl_Smtp.Quit(c);
exception
when Utl_Smtp.Invalid_Operation then
Dbms_Output.Put_Line(' Invalid Operation in Mail attempt
using UTL_SMTP.');
when Utl_Smtp.Transient_Error then
Dbms_Output.Put_Line(' Temporary e-mail issue - try again');
when Utl_Smtp.Permanent_Error then
Dbms_Output.Put_Line(' Permanent Error Encountered.');
end;
And when i am trying to call the procedure to send email it gives error please help me out i want to send email .let me know where is my mistake.
I have grant all commands
GRANT EXECUTE ON UTL_TCP TO admonline;
GRANT EXECUTE ON UTL_SMTP TO admonline;
GRANT EXECUTE ON UTL_MAIL TO admonline;
GRANT EXECUTE ON UTL_http TO admonline;
--Calling procedure
BEGIN
send_mail(msg_to => 'waqasprince911#gmail.com',
msg_subject => 'Test subject',
msg_text => 'Test text');
END;
Error is Mention
Certificate validation failure
ORA-06512: at "SYS.UTL_TCP", line 59
ORA-06512: at "SYS.UTL_TCP", line 284
ORA-06512: at "SYS.UTL_SMTP", line 284
ORA-06512: at "SYS.UTL_SMTP", line 289
ORA-06512: at "ADMONLINE.SEND_MAIL", line 11
ORA-06512: at line 2
29024. 00000 - "Certificate validation failure"
*Cause: The certificate sent by the other side could not be validated. This may occur if
the certificate has expired, has been revoked, or is invalid for another reason.
*Action: Check the certificate to determine whether it is valid. Obtain a new certificate,
alert the sender that the certificate has failed, or resend.
The error seems pretty clear. Try googliing for UTL_SMTP , certificate and 29024. 00000 - "Certificate validation failure" also read the docs on how to use this package. It would seem to be a failure of the security certificate.
A quick google turned up this,
Also, as a noob, remember you are asking us to take time out of our day to help you. Help us by always including version of product and what steps you have tried and the result and what searches and investigation you have tried.
these may help:
https://mathijsbruggink.com/2013/10/24/sending-mail-from-an-11g-oracle-database-utl_smtp/ https://community.oracle.com/thread/930797 http://www.dadbm.com/enable-oracle-database-to-send-emails-via-smtp-server/ https://community.oracle.com/thread/368259
https://community.oracle.com/thread/4089002 https://oracle-base.com/articles/misc/utl_http-and-ssl
https://docs.oracle.com/database/121/ARPLS/u_smtp.htm#ARPLS074
https://oracle-base.com/articles/misc/email-from-oracle-plsql
Related
I would call a web service from PL/SQL Oracle 11g but the following script is not working:
declare
v_Endpoint varchar2(500) := '<my_endpoint>';
v_Http_Req Utl_Http.Req;
begin
Utl_Http.Set_Wallet('<my_wallet_path>','<my_wallet_password>');
Utl_Http.Set_Proxy('<proxy_url>:<proxy_password>#<proxy-url>:8080');
v_Http_Req := Utl_Http.Begin_Request(v_Endpoint, 'POST', 'HTTP/1.1');
exception
when others then
DBMS_OUTPUT.PUT_LINE('EXCEPTION: '||SQLERRM);
DBMS_OUTPUT.PUT_LINE('EXCEPTION: '||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
DBMS_OUTPUT.PUT_LINE('EXCEPTION: '||UTL_HTTP.GET_DETAILED_SQLERRM);
end;
EXCEPTION: ORA-29273: richiesta HTTP non riuscita
ORA-06512: a "SYS.UTL_HTTP", line 1130
ORA-53203: violazione di sicurezza
EXCEPTION: ORA-06512: a "SYS.UTL_HTTP", line 1130
ORA-06512: a line 7
EXCEPTION: ORA-53203: violazione di sicurezza
Procedura PL/SQL completata correttamente.
The connection to the endpoint is possible with SOAPUI without problems. I can open the URL in a browser with the proxy <proxy_url>:8080/script_proxy.pac
The wallet contains the certificate that has been downloaded from .
I've inserted the URL test.salesforce.com in the ACL and granted access to the user that runs my script.
How can I figure out the issue?
You probably need to define an ACL to access external network services. Check the output of:
SELECT * FROM DBA_NETWORK_ACLS;
SELECT * FROM DBA_NETWORK_ACL_PRIVILEGES;
And check the documentation to the CREATE_ACL Procedure:
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
acl IN VARCHAR2,
description IN VARCHAR2,
principal IN VARCHAR2,
is_grant IN BOOLEAN,
privilege IN VARCHAR2,
start_date IN TIMESTAMP WITH TIMEZONE DEFAULT NULL,
end_date IN TIMESTAMP WITH TIMEZONE DEFAULT NULL );
I run the write_test procedure, which works good.
begin
koll_data_pkg.write_test(p_customer_id=>247, p_addr=>'address', p_dir=>'\\SERVER01\Backup\Log\');
end;
But, when I change value of p_dir to another directory p_dir=>\SERVER12\Backup\Log\ it gives following error:
ORA-29283: invalid file operation
ORA-06512: by "SYS.UTL_FILE",
ORA-29283: invalid file operation
ORA-06512: by "DATA_PKG",
ORA-06512: by line
I have tried give permission using following commands, but still same error:
CREATE OR REPLACE DIRECTORY DEVO_INVREC_DIR AS '\\SERVER12\Backup\Log\';
GRANT READ, WRITE ON DIRECTORY DEVO_INVREC_DIR TO USER1;
GRANT READ, WRITE ON DIRECTORY DEVO_INVREC_DIR TO USER1;
GRANT EXECUTE ON UTL_FILE TO USER1;
Procedure:
procedure write_test(p_customer_id in koll_customer_party.customer_id%type,
p_addr in varchar,
p_dir in varchar,
p_filename in varchar2 default null)
is
lt_id id_tt;
lt_bolagsnamn bolagsnamn_tt;
l_file utl_file.file_type;
l_line varchar2(2048);
l_name varchar2(300):= 'DEVO_INVREC_DIR';
l_filename varchar2(100):= 'testfile.txt';
l_sql varchar2(512);
begin
select devo_id, bolagsnamn
bulk collect into lt_id, lt_bolagsnamn
from documents where customer_id=p_customer_id
if lt_id.count > 0 then
l_sql := 'create or replace directory ' || l_name || ' as ''' || p_dir || '''';
execute immediate l_sql;
if p_filename is not null then
l_filename := p_filename;
end if;
l_file := utl_file.fopen(l_name,l_filename,'w');
if utl_file.is_open(l_file) is not null then
for i in lt_id.first .. lt_devo_id.last loop
l_line:= lt_id(i) || ';' || replace(lt_bolagsnamn(i),';','');
utl_file.put_line(l_file, l_line);
end loop;
end if;
utl_file.fclose(l_file);
end if;
end;
Check out this forum response: https://community.oracle.com/thread/4145239?start=0&tstart=0
In summary, Oracle can't access the network shares in its default installed configuration because the Windows SYSTEM user can't access network shares by definition. You either have to reconfigure Oracle to run as a user other than SYSTEM, with permissions on the share, or allow SYSTEM to access network shares (a HUGE security risk). I was going to include a link describing how to change the user to be another service account, but they all seem to be broken or removed. It may depend on your exact version of Oracle and Windows, too, so you're best bet in the absence of other documentation would be to contact Oracle Support. There is no simple PL/SQL programming answer to your problem.
I've been trying to get Oracle to call a REST API. While getting things set up and running we ran into an issue where our code generates an ORA-53203: security violation. In the process of isolating the issue we set up a procedure to test the connection and this, too, generates the same error.
We are using Oracle 12c and we've set up ACE/ACL entries for the host we're testing with for both 'connect' and 'resolve' permissions.
create or replace procedure showTitleTag ( i_url in varchar2 )
AS
l_httpreq UTL_HTTP.req;
l_httpresp UTL_HTTP.resp;
l_text varchar2(32767);
l_response CLOB;
l_title varchar2(32767);
BEGIN
l_httpreq := UTL_HTTP.begin_request(i_url);
l_httpresp := UTL_HTTP.get_response(l_httpreq);
BEGIN
LOOP
UTL_HTTP.read_text(l_httpresp, l_text, 32766);
l_response := l_response || l_text;
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
UTL_HTTP.end_response(l_httpresp);
END;
l_title := REGEXP_REPLACE(l_response, '.*<title> ?(.+) ?</title>.*', '\1', 1, 1, 'in');
DBMS_OUTPUT.put_line(l_title);
EXCEPTION
WHEN OTHERS THEN
UTL_HTTP.end_response(l_httpresp);
RAISE;
END;
This code, should give us the contents of the web-page's title tag (we used "http://www.redhat.com" as our test URL). Instead we receive the following errors:
ORA-29273: HTTP request failed
ORA-53203: security violation
ORA-06512: at "APPS.SHOWTITLETAG", line 29
ORA-06512: at line 1
You need to make sure the related access control list (ACL) assigned and the right privilege has been granted to your target host.
If there's no problem with the first, then look
(select a.lower_port, a.upper_port from dba_network_acls a where a.host like '%i_url%')
whether you defined an interval for the ports of your URL, and
contains the port of the target host(s).
I am trying to write a simple function to verify whether a url is valid.
I started with an anonymous block that looks like;
DECLARE
httpuri HTTPURIType;
y CLOB;
x BLOB;
BEGIN
httpuri := HTTPURIType('http://google.com');
BEGIN
DBMS_OUTPUT.put_line(httpuri.getContentType());
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line('Bad Url');
END;
END;
/
This works fine, it outputs a "Bad Url" when the url is bad, and the mime type other wise.
Great let's write a function to encapsulate everything;
CREATE OR REPLACE FUNCTION CHECK_URL
(
URL_IN IN VARCHAR2
) RETURN VARCHAR2 AS
HTTPURI HTTPURIType;
OUT_STRING VARCHAR2(32767);
BEGIN
HTTPURI := HTTPURITYPE(URL_IN);
BEGIN
OUT_STRING := HTTPURI.GETCONTENTTYPE();
EXCEPTION
WHEN OTHERS
THEN
OUT_STRING := 'Error: Bad URL-' || URL_IN;
END;
RETURN OUT_STRING;
END CHECK_URL;
I call it with;
SELECT CHECK_URL('http://google.com') FROM DUAL;
or
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(CHECK_URL('http://google.com'));
END;
/
This always returns "Error: Bad URL-" followed by the url entered. When I take out the exception handler, it gives the following error;
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "SYS.HTTPURITYPE", line 123
ORA-06512: at "LMSADMIN.CHECK_URL", line 10
29273. 00000 - "HTTP request failed"
*Cause: The UTL_HTTP package failed to execute the HTTP request.
*Action: Use get_detailed_sqlerrm to check the detailed error message.
Fix the error and retry the HTTP request.
I have a minimal understanding of ACL lists. I am running both sets of code as the same user so I am not sure why I get differing results.
Edit: Database Version - 12c R2.
I'm trying to run a shell scrpit which executes a SQL. Within the SQL file I have queries which check something from the database and when one of the checks fail, it tirggers an email alert to the id's specified.
My code is something like:
Declare
numrows number(4,2);
c UTL_SMTP.CONNECTION;
PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
BEGIN
UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
END;
Begin
select count (*) into numrows
<some sub queries>
Minus
select count(*)
<from something else>
;
--if differences are found, then trigger an email.
IF numrows <> 0 THEN
BEGIN
c := UTL_SMTP.OPEN_CONNECTION('localhost',25);
UTL_SMTP.HELO(c, 'localhost');
UTL_SMTP.MAIL(c, 'a#b.com');
UTL_SMTP.RCPT(c, 'c#d.com');
UTL_SMTP.OPEN_DATA(c);
send_header('From', '"noreply" <a#b.com>');
send_header('To', '"c#d.com');
send_header('Subject', '<subject here>');
UTL_SMTP.WRITE_DATA(c,'brief error message'|| chr(13));
FOR I IN (
<some logic>
)
LOOP
UTL_SMTP.WRITE_DATA(c, xyz || ' - ');
UTL_SMTP.WRITE_DATA(c, qwe );
UTL_SMTP.WRITE_DATA(c,UTL_TCP.CRLF);
END LOOP;
UTL_SMTP.WRITE_DATA(c, chr(13)||'-Sent by the batch process.');
UTL_SMTP.CLOSE_DATA(c);
UTL_SMTP.QUIT(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
UTL_SMTP.QUIT(c);
EXCEPTION
WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
NULL; -- When the SMTP server is down or unavailable, we don't have
-- a connection to the server. The QUIT call will raise an
-- exception that we can ignore.
END;
raise_application_error(-20000,
'Failed to send mail due to the following error: ' || sqlerrm);
END;
END IF;
END;
Now the errors I get are:
SP2-0027: Input is too long (> 2499 characters) - line ignored
SQL> SP2-0734: unknown command beginning "ggg..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "ddd..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "eee..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "nnn..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL> SP2-0734: unknown command beginning "hfhf..." - rest of line ignored.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
I looked up the SP2-0027 and I gathered that the input line has more than 2499 characters. None of my input lines have so many characters and the total character count on the SQL file itself is about 4000.
I don't know if there is any internal implementation of UTL_SMTP that is passing in some data behind the scenes. Or if there is something else that is happening.
This runs perfectly when using TOAD.
Can someone help?
I think I've found an answer:
All I had to do was to split the SQL file which the shell script was executing into 2 files and volia` it worked :D
#tbone: fyi & thanks for your help!