Hey Guys I need Help How to send EMAIL Automatically in oracle APEX, I know some using DBMS_SCHEDULER we can achieve it, I have no idea how to do it where to start any suggestion, Along with that i want to attach a report. COuld you help me?
Can you Suggestest any blog?
Thank You in Advance.......
This blog is a good place to start: https://blogs.oracle.com/apex/creating-email-campaign-app-with-oracle-apex
The code below as long as the owner of the job is a schema that has been provisioned for the APEX workspace, or the schema has been granted the role APEX_ADMINISTRATOR_ROLE. You will need to substitute 100 for your actual application number and 1 with an actual page in that application. The third parameter is the username and can be anything.
DECLARE
l_mail_id NUMBER;
BEGIN
apex_session.create_session (100, 1, 'send_email');
l_mail_id :=
apex_mail.send (p_to => 'youremail#gmail.com',
p_from => 'nobody#test.com',
p_body => 'plaintext body',
p_body_html => '<h1>HTML Body</h1>',
p_subj => 'Test Email Subject');
apex_mail.add_attachment (p_mail_id => l_mail_id,
p_attachment => EMPTY_BLOB (),
p_filename => 'attachment_name.json',
p_mime_type => 'application/json');
apex_mail.push_queue;
apex_session.delete_session;
END;
/
Related
I have some problems when trying to solve my homework about VPD Policy of Oracle. The question is "MYADMIN account has the right to select and update students' Enroll Information. But he is not allowed to see the Score of the student's Enroll Information as well as update the Score of the student's Enroll Information.
I have done the first task (they are not allowed to see the Score of the student's Enroll Information by using column masking), but when I trying to add the word "update" to statement_type to my code like this, the DBMS notifies errors. I have searched the Internet and realized that column masking can be only used for "Select" statment.
So if I want to apply the Oracle VPD Policy to restrict MYADMIN to update the Score of students' Enroll Information. How can I do that? Will I have to create a session_context view?
Here is my code. Thank you so much
CREATE OR REPLACE FUNCTION Question5
(p_schema IN VARCHAR2, p_object IN VARCHAR2)
RETURN VARCHAR2
AS
user_value VARCHAR2(60);
user varchar2(60);
BEGIN
user := SYS_CONTEXT('userenv','session_user');
user_value:= '(select (SYS_CONTEXT(''USERENV'',''SESSION_USER'')) from dual)';
IF(UPPER(user) = 'MYADMIN') THEN
RETURN 'USER != ''MYADMIN''';
ELSE
RETURN 'StudentID = ' || user_value;
END IF;
END;
/
BEGIN
DBMS_RLS.ADD_POLICY(
object_schema =>'SYSTEM',
object_name => 'EnrollInformation',
policy_name => 'Question5_MyAdmin',
statement_types => 'select, update',
function_schema => 'sec_mgr',
policy_function => 'Question5',
sec_relevant_cols => 'Score',
sec_relevant_cols_opt => dbms_rls.all_rows,
update_check => TRUE);
end;
/
I m trying to crate notification to send email whenever job is broken. This is the job:
declare
jobno number;
begin
dbms_job.submit( jobno,
'test_job_procedure;',
SYSDATE,
'SYSDATE + 1/24 /12');
commit;
end;
This is configuration of credentials :
BEGIN
DBMS_SCHEDULER.create_credential (credential_name => 'MAILSERVER_CREDENTIAL',
username => 'test#gmail.com',
password => 'test');
END;
BEGIN
DBMS_SCHEDULER.set_scheduler_attribute ('email_server', 'smtp.gmail.com:587');
DBMS_SCHEDULER.set_scheduler_attribute ('email_sender', 'test#gmail.com');
DBMS_SCHEDULER.set_scheduler_attribute ('email_server_credential', 'MAILSERVER_CRED
ENTIAL');
END;
And this is email notification scheduler: Instead of what there was job_name but in dbms_job job names are numbers which are non consistent, when I restart the job it gets new number so I put WHAT as something that will recognize that job. I don't know if this could work because I am getting error at the end but anyway when i run this select
SELECT *
FROM all_scheduler_global_attribute
I get this results https://imgur.com/a/FnQJ7
And this is job email notification :
BEGIN
DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
what => 'test_job_procedure',
recipients => 'test1#gmail.com',
sender => 'test#gmail.com',
subject => 'Scheduler Job Notification',
body => '%event_type% occurred at %event_timestamp%. %error_message%',
events => 'JOB_FAILED, JOB_BROKEN');
END;
can someone please go through this and tell me where am I making mistakes ?
I have an apex application where i need to send a notification mail to all the employees on the 5th of every month. So just for the sake of testing i am trying to send a mail in every 30 seconds. I created a job scheduler on a procedure to do the same. Here is the PLSQL code for it.
create or replace procedure send_notification_employee as
cursor c_employee is select * from EMPLOYEE;
r_employee c_employee%ROWTYPE;
begin
open c_employee;
loop
fetch c_employee into r_employee;
exit when c_employee%NOTFOUND;
APEX_MAIL.SEND(
p_to => r_employee.EMPLOYEE_EMAIL,
p_from => 'abc#gmail.com',
p_subj => 'Reminder : Meeting',
p_body => '<Some random message>');
end loop;
close c_employee;
end;
/
begin
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'send_notification',
job_type => 'stored_procedure',
job_action => 'send_notification_employee',
start_date => NULL,
repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
end_date => NULL);
end;
/
begin
DBMS_SCHEDULER.enable(
name => 'send_notification');
end;
/
I guess the code is correct. The only thing i am not sure of is to how to run this scheduler on the apex oracle application. Should i just execute these statements on the SQL Commands or is there any other way to do it?
Also i tried to execute the same statements in the SQL Commands tab but i don't receive any mails as such. Is there any issue with my code? Thanks in advance.
You need to set the security group if sending the mail from the database rather than from APEX directly. You should also use push_queue at the end of the procedure to clear out the table of unsent mail.
create or replace procedure send_notification_employee as
cursor c_employee is select * from EMPLOYEE;
r_employee c_employee%ROWTYPE;
l_workspace number;
begin
-- Get a valid workspace ID
SELECT MAX(workspace_id) INTO l_workspace FROM apex_applications WHERE application_id = <valid application_id>;
-- Set Workspace
wwv_flow_api.set_security_group_id(l_workspace);
open c_employee;
loop
fetch c_employee into r_employee;
exit when c_employee%NOTFOUND;
APEX_MAIL.SEND(
p_to => r_employee.EMPLOYEE_EMAIL,
p_from => 'abc#gmail.com',
p_subj => 'Reminder : Meeting',
p_body => '<Some random message>');
end loop;
close c_employee;
-- Finally force send
APEX_MAIL.PUSH_QUEUE;
end;
Re. how to execute - it depends on what you want to do. If you just want to run it on the 5th of every month just setup a scheduled job in the db to do it, as you have above. If you want to run on an adhoc basis just create a job in an APEX after submit process that calls the procedure and executes through the database.
As an aside, if you plan to create many mail procedures you may wish to create a helper procedure to get the workspace id / send the mail, and just call it from your other mail procedures.
These queries could be handy (To check if you have the correct set up):
Check if util_smtp is installed:
select * from dba_objects where object_name like 'UTL_SMTP%'
Check privileges:
select grantee , table_name , privilege from dba_tab_privs where table_name = 'UTL_SMTP'
Check open network hosts, ports:
select acl , host , lower_port , upper_port from DBA_NETWORK_ACLS;
Check network privileges:
select acl , principal , privilege , is_grant from DBA_NETWORK_ACL_PRIVILEGES
I'm currently using the Apex context to deploy a page created directly from PLSQL, I need to use the "Shared Components/Items" to store some dynamic values for the user and then be destroyed when the context is destroyed.
I'm using the Items but I couldn't find a way to create them dynamically from PLSQL so I'm looking for a replacement to this app behavior.
This is my current solution:
APEX_UTIL.SET_SESSION_STATE (p_name => 'Item_Name',
p_value => 'Item Value');
But this is not possible with dynamic Items or Variables,
What would you suggest?
Thanks for your answer.
Solution for this:
Collections
APEX_COLLECTION.CREATE_COLLECTION(
p_collection_name IN VARCHAR2);
--and to add a value
Begin
APEX_COLLECTION.ADD_MEMBERS(
p_collection_name => 'EMPLOYEE',
p_c001 => l_arr1,
p_c002 => 1_arr2);
End;
See documentation for more information:
https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_collection.htm#AEAPI531
I want to redirect the post login page to a change login page.
I have a custom authentication schema which call user_mng.authenticate as authentication function.
function authenticate(p_username in VARCHAR2, p_password in VARCHAR2) RETURN BOOLEAN IS
ntype int;
pwobf varchar2(100);
BEGIN
pwobf:=obfuscate(nvl(p_password,'**'));
select user_role
into ntype
from( select 1 user_role
from view_users
where upper(user_id)=upper(p_username)
and password=p_password
union all
select 2 user_role
from view_users
where upper(user_id)=upper(p_username)
and password=pwobf);
apex_util.set_authentication_result(0);
RETURN TRUE;
exception when no_data_found then
apex_util.set_authentication_result(1);
return false;
END authenticate;
you can find below a printscreen of the login page
http://gyazo.com/10dc90b9e271ae11fadfa48201665a3d.png
The login page is pretty much the one automatically created by APEX where in the post submit LOGIN process I have added
begin APEX_CUSTOM_AUTH.LOGIN (
p_uname => :P101_USERNAME,
p_password => :P101_PASSWORD,
p_session_id => V('APP_SESSION'),
p_app_page => :APP_ID||':18');end;
where page 18 is my target page while 1 is the home page.
I don't know why, most of the time the page is sent to the home... I haven't be able to relate to any other condition but from time to time it goes to the change login page. If in the p_app_page => :APP_ID||':18' I set an invalid page a receive an error (the page is being read) as well if I set an invalid password (the auth. process is working) during the login.
I've tried to clean browser cache... but it does not appear to have any effect.
I'm using Apex 4.2.4 with Tomcat 7.
I would deeply appreciate any help.
Regards
the villain is the deep link. Solved as follows
declare
vpg varchar2(10):=':1';
begin
APEX_UTIL.SET_SESSION_STATE('FSP_AFTER_LOGIN_URL');
IF user_mng.need_psw_rst(:P101_USERNAME) then
vpg:=':18';
end if;
APEX_CUSTOM_AUTH.LOGIN (
P_UNAME => :P101_USERNAME,
P_PASSWORD => :P101_PASSWORD,
P_SESSION_ID => v('APP_SESSION'),
p_app_page => :APP_ID||vpg
);
end;