Solved

automatic email alert

Posted on 2016-11-23
1
40 Views
Last Modified: 2016-11-24
hi experts,

i have two tables. in table1 i have two columns (store,email),in table2 i have two columns (store,logs). In table1 ,for one particular store we have only one email id associated. but in table2 with one particular store we will have multiple logs. What i need to do is i need to send an email to that email id with which the store is attached in table1 and in the body of that email i will have the names of the logs associated with that store in table2. I need to use plsql query for this. please help me with this issue. i have attached the screenshorts of demo tables.

thanks.
table2.PNG
table1.PNG
0
Comment
Question by:sam shah
1 Comment
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 41899087
Do you need to send the file names or the contents of those files?

If the contents, where are the files?
And, should the contents be written into the body of the email, or sent as attachments?


If you only need to send the file names, then something like this should work...

DECLARE
    v_connection   UTL_SMTP.connection;
BEGIN
    FOR e IN (SELECT e.store, e.email
                FROM store_emails e
               WHERE e.store IN (SELECT l.store
                                   FROM store_logs))
    LOOP
        v_connection := UTL_SMTP.open_connection('your.email.server.com');
        UTL_SMTP.helo(v_connection, 'your.domain.com');
        UTL_SMTP.mail(v_connection, 'your_return_address@your.domain.com');
        UTL_SMTP.rcpt(v_connection, e.email);
        UTL_SMTP.open_data(v_connection);

        UTL_SMTP.write_data(v_connection, 'From: Your Name' || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'To: ' || e.email || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'Subject: Store Logs' || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);

        -- This is easy and likely sufficient for short emails
        -- but, if your email body becomes large
        -- you may want to construct it as a clob before connecting to the email server
        -- then write the clob into the email body so you don't get timeouts
        FOR l IN (SELECT logs
                    FROM store_logs l
                   WHERE l.store = e.store)
        LOOP
            UTL_SMTP.write_data(v_connection, l.logs || UTL_TCP.crlf);
        END LOOP;

        UTL_SMTP.close_data(v_connection);
        UTL_SMTP.quit(v_connection);
    END LOOP;
EXCEPTION
    WHEN OTHERS
    THEN
        DBMS_OUTPUT.put_line(DBMS_UTILITY.format_error_stack);
END;

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle 10g - insert string with special characters 8 41
Export import database 4 39
selective queries 7 21
SQL Server - Slabs 9 35
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now