How to generate a email from a stored procedure using a mail server or outlook in Oracle


I need a code to generate a email from a stored procedure in Oracle using Outlook or a mail server. If is possible we prefer Outlook
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

as long as your can communicate via SMTP protocol it doesn't matter what type of email server you have.

Simple example...

    v_connection   UTL_SMTP.connection;
    v_connection := UTL_SMTP.open_connection('');
    UTL_SMTP.helo(v_connection, '');
    UTL_SMTP.mail(v_connection, '');
    UTL_SMTP.rcpt(v_connection, '');

    UTL_SMTP.write_data (v_connection,
                         'From: test from address' || UTL_TCP.crlf
    UTL_SMTP.write_data (v_connection, 'To: test to address' || UTL_TCP.crlf);
    UTL_SMTP.write_data (v_connection,
                         'Subject: test subject' || UTL_TCP.crlf);
    UTL_SMTP.write_data (v_connection, UTL_TCP.crlf);
    UTL_SMTP.write_data (v_connection, 'test body' || UTL_TCP.crlf);
    UTL_SMTP.close_data (v_connection);
    UTL_SMTP.quit (v_connection);
        DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);

You might also want to review extended authentication in this article

or attachments with

you might be able to use utl_mail  but it is very limited, not installed by default and not extensible.  So I don't bother.  Using utl_smtp is pretty easy, and as shown in the article you can build your own wrapper functions to encapsulate more complex functionality with a simple api if needed

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
note, Outlook is simply an email client.  It's not really involved in the sending of the email.  You can certainly send email from Oracle to someone using Outlook though.  I have outlook myself and receive messages from oracle databases using code much like the example above and in the articles.
Also note in 11g or higher, you have to configure network access via ACLs

You'll use the DBMS_NETWORK_ACL_ADMIN package to do that.

You can find instructions for using that package, including examples here...

and part 2 here
joyacv2Author Commented:

Do you know some additional code to use Outlook to send the message, so any user can use his personal email to send the email in the machine?
Change these lines...

    UTL_SMTP.mail(v_connection, '');

UTL_SMTP.write_data (v_connection,
                         'From: test from address' || UTL_TCP.crlf

and your email will be addressed from whomever you want.

Note the "From: ....." line is really just a comment.
 The utl_smtp.mail procedure is what really determines the from.  It's simply convention that most email systems put the address in the "From" line.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.