I want to create a trigger to send automatic emails to the mail addresses on personal table when there is a change on the other table like 'city' on SQL*Plus.
But I could not find a way to create this trigger, could you please help me?
First: This is not SQLPlus but Oracle SQL we are talking here - and actually you do have to write PL/SQL code for that, like in any trigger in Oracle.
But you can use SQLPlus for that - or SQLdeveloper or any other tool which poses as database client.
How to send mails in PL/SQL:
UTL_MAIL.SEND ('sender#myapp.com','receiver#yourapp.com',
message => 'this is the message',
subject => 'Warnung: message arriving');
But your DBA must have configured the SMTP server for the database and you need appropriate privileges to send a mail.
Related
I have a webapp designed in asp.net mvc that sends emails via smtp no problem via on click event. But i need a way to automatically check every month for a certification if it is expired and email that user. I am reading sql server or windows service. Which do you recommend and could you provide your link for me to read up on it. Thanks.
Why bother? Sql Server doesn't care about the expiry date...
Joking aside, you'll probably notice that there are a number of internal certs that come with Sql Server that have expired. MS doesn't care about those but you should probably make sure you ignore them in any alert you receive.
You could use a policy (SSMS\Management\Policies) to alert you, something like:
Declare #object_set_id Int
Exec msdb.dbo.sp_syspolicy_add_object_set #object_set_name=N'Certs_ObjectSet', #facet=N'Certificate', #object_set_id=#object_set_id Output
Select #object_set_id
Declare #target_set_id Int
Exec msdb.dbo.sp_syspolicy_add_target_set #object_set_name=N'Certs_ObjectSet', #type_skeleton=N'Server/Database/Certificate', #type=N'CERTIFICATE', #enabled=True, #target_set_id=#target_set_id Output
Select #target_set_id
Exec msdb.dbo.sp_syspolicy_add_target_set_level #target_set_id=#target_set_id, #type_skeleton=N'Server/Database/Certificate', #level_name=N'Certificate', #condition_name=N'', #target_set_level_id=0
Exec msdb.dbo.sp_syspolicy_add_target_set_level #target_set_id=#target_set_id, #type_skeleton=N'Server/Database', #level_name=N'Database', #condition_name=N'', #target_set_level_id=0
Go
Declare #policy_id Int
Exec msdb.dbo.sp_syspolicy_add_policy #name=N'Certs', #condition_name=N'Certs', #execution_mode=0, #policy_id=#policy_id Output, #object_set=N'Certs_ObjectSet'
Select #policy_id
Have to send email from oracle apex using APEX_MAIL.SEND() method.
I am using the code:
BEGIN
apex_mail.send(p_to => 'tanmoydawn#gmail.com'/*l_to_addr*/,
p_from => 'tanmoydawn#gmail.com'/*l_from_addr*/,
p_bcc => l_bcc_addr,
p_subj => l_mail_sub,
p_body => 'Service Request ' || :mail_body ||
'Note:- This is a system generated Email. Please DO NOT REPLY to it.');
apex_mail.push_queue;
EXCEPTION
when others then
INSERT INTO send_mail_error_test VALUES ('Send_mail',systimestamp,:service_request_id||'-err:'||seq_service_req_error_id.NEXTVAL);
COMMIT;
END;
*** all the variables contain correct values
Working with a database and that database has ACL(access control list) access
In apex administrative services, Configured instance settings for email as hostname, port , email provisioning enabled.
UTL_SMTP package is installed
From the same process, at the same point of control flow a code to send mail using utl_Smtp is working fine, though that apex_mail.send() is not working.
That apex_mail.send() is not giving any error or exception, but i am not recieving email from it.
Have one confusion, got some solutions like that, 'APEX_040200' should have been added to ACL. But the database I am using and implementing the code on it, say 'apex_user' is already added to ACL. Even now do I have to add 'APEX_040200' or 'APEX_050200' to ACL?
can anyone help me out and give me a fruitful solution? I am using apex 5.0.2.00.07.
As can be found in the apex_mail api documentation:
Before you can send email from an Application Builder application, you
must:
Log in to Oracle Application Express Administration Services and
configure the email settings on the Instance Settings page. See
"Configuring Email" in Oracle Application Express Administration Guide.
If you are running Oracle Application Express with Oracle Database 11g
release 1 (11.1), you must enable outbound mail. In Oracle Database
11g release 1 (11.1), the ability to interact with network services is
disabled by default. See "Enabling Network Services in Oracle Database
11g" in Oracle Application Express Application Builder User's Guide.
You specified instance settings are ok. Your "database has ALC access" doesn't mean anything. Do you mean you have a database which uses network ACLs? (11g or higher)
That same documentation links to "the Enabling Network Services in Oracle Database 11g or Later" documentation
This document does not leave you guessing:
By default, the ability to interact with network services is disabled
in Oracle Database 11g Release 1 or 2 or later. Therefore, if you are
running Oracle Application Express with Oracle Database 11g Release 1
or 2 or later, you must use the new DBMS_NETWORK_ACL_ADMIN package to
grant connect privileges to any host for the APEX_050000 database
user. Failing to grant these privileges results in issues with:...
If you have an older version of apex, eg 4.2, the user to grant to is another one, and can be found in the documentation. Alternatively, you can just find out
by for example querying the ALL_USERS view and find the APEX_###### users, pick the one with the highest version number:
select *
from all_users
where username like 'APEX%'
order by username;
in our case, it was a job, ORACLE_APEX_MAIL_QUEUE, which had status 'RUNNING' for 8 days. Apparently, it held some kind of lock on the queue or mailprocess
We killed the job and that was it.
(see dba_scheduler_jobs for the job & status)
I guess you should do as they say here, but with the proper APEX version, as you guessed... try various, with APEX_050000 (rather than APEX_050200 that would imply APEX 5.2 - not released yet):
DECLARE
ACL_PATH VARCHAR2(4000);
BEGIN
-- Look for the ACL currently assigned to '*' and give APEX_050000
-- the "connect" privilege if APEX_050000
-- does not have the privilege yet.
SELECT ACL INTO ACL_PATH FROM DBA_NETWORK_ACLS
WHERE HOST = '*' AND LOWER_PORT IS NULL AND UPPER_PORT IS NULL;
IF DBMS_NETWORK_ACL_ADMIN.CHECK_PRIVILEGE (ACL_PATH,'APEX_050000','connect') IS NULL THEN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(ACL_PATH,'APEX_050000', TRUE, 'connect');
END IF;
EXCEPTION
-- When no ACL has been assigned to '*'.
WHEN NO_DATA_FOUND THEN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL('power_users.xml',
'ACL that lets power users to connect to everywhere',
'APEX_050000', TRUE, 'connect');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL('power_users.xml','*');
END;
/
COMMIT;
I had this same problem. Could send email using utl_smtp, but could not with apex_mail.send. Turned out I had an extra space in the smtp server url.
Email server for APEX is setup in the APEX Instance workspace. Check "Manage Instance' > 'Instance Settings' > 'Email' > 'SMTP Host Address'
Also try checking the Logs in 'Monitor Activity' in the Instance Workspace.
Hi Oracle Database Gurus,
What is the issue suddently the Database stopped sending Emails out after it is upgraded from Oracle 10g to 11g R1? I double check the email demon on the server it is working fine when I send an email from the linux command line (not through an database procedue). And the smtp_out_server parameter value is the same before and after the upgrade...
Thanks!
Do you get any errors? The first thing that jumps to mind is that 11g introduces more fine-grained permissions for packages like UTL_MAIL and UTL_SMTP that interact with other servers. Your DBA would need to create an appropriate network ACL in order to allow you to access external servers from within your PL/SQL code.
If you don't have sufficient permission, your code should be getting an "ORA-24247: network access denied by access control list (ACL)" error. Are you getting such an error? Or is it possible that you have a WHEN OTHERS exception handler that is hiding that error from you?
Do you see any rows in USER_NETWORK_ACL_PRIVILEGES (or DBA_NETWORK_ACL_PRIVILEGES or ALL_NETWORK_ACL_PRIVILEGES depending on what user you're logging in as, what user is sending mail, and your privilege level)? If so, is there a row for your mail server with whatever port range your SMTP server is listening on?
Try to be more clear, I'm in lack of ideas in this problem, even it sounds like a classic.
My application is running on weblogic 10.3.3 application server, and for database I am using Oracle database 11g. My problem is that there is table in db, let's say "user.", there is column, let's say "columnA", in this table. This table is updating by some module of application.
What I want if when value of column is "abc.", then I have to show alert to console(IP). {IP can be retrieved from DB as it is configured in DB. this ip will be other linux system other than linux machine where oracle database is installed.} Updating is continuously done on my table from module of application. Please tell me from where should I start?, what should I read. I am not able to understand what should be approach. Any help is much appreciated.
Can u provide me any begginner.s link of oracle db listener?
You probably want to look at setting up a Trigger in the database
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/triggers.htm
An alternative to a trigger would be to log update queries against the table (to a log file) and have a process monitor the log, sending out alerts when something happens.
I am writing an web-application which needs to receive e-mail messages to users' internal email addresses, let administrators approve them, and then forward to corresponding user's external mailbox.
I have installed and configured postfix for message receiving task. It uses virtual e-mail addresses, and my existing database where user email addresses are stored. Local email storage is maildir and I use postfix's virtual MDA.
Basically, I would like to execute a script every time a new message is received, and for which user (maildir message id would be very helpful too). Then I could read the message from python code (python had a module for maildir messageboxes) and insert it in database.
I can think of three ways to do this:
iterate user maildirs and check
if there are any new messages, but it would be ineffective for large number of users.
use dbmail and then check if there are any new messages in database (this would be quicker, but I'd have to configure everything from scratch). Besides, existing user data tables cannot be used.
write a wrapper around maildrop/virtual to save message in db and in maildir as well, but I'd need a way to check if received message is valid and successfully saved by the real MDA.
Any suggestions appreciated!
In the /etc/aliases file you can specifiy a program which gets executed everytime a user recieves a mail. This program gets the mail on stdin. So you dont have to poll and your program gets run instantly.
In response to my own question, I used postfix content_filter with X flag set in pipe and process receiving address and message manually. Since I didn't need to access messages in maildir, this approach works fine for me.