How to call the Linux sendemail program from within Oracle

Asked

Viewed 87 times

1

I know that the Oracle has a package for this (UTL_SMTP), but I would like to use the Linux sendmail.

Does anyone have any example of code or know where the documentation of Oracle about this ?

1 answer

1

There is unofficial documentation on this page:

And I make a point of setting the example they provide here by believing to be a great example:

The easiest way to send an email is through the following procedure:

    CREATE OR REPLACE PROCEDURE send_mail (p_to        IN VARCHAR2,
                                           p_from      IN VARCHAR2,
                                           p_message   IN VARCHAR2,
                                           p_smtp_host IN VARCHAR2,
                                           p_smtp_port IN NUMBER DEFAULT 25)
    AS
      l_mail_conn   UTL_SMTP.connection;
    BEGIN
      l_mail_conn := UTL_SMTP.open_connection(p_smtp_host, p_smtp_port);
      UTL_SMTP.helo(l_mail_conn, p_smtp_host);
      UTL_SMTP.mail(l_mail_conn, p_from);
      UTL_SMTP.rcpt(l_mail_conn, p_to);
      UTL_SMTP.data(l_mail_conn, p_message || UTL_TCP.crlf || UTL_TCP.crlf);
      UTL_SMTP.quit(l_mail_conn);
    END;
    /

The code below shows how to call such a procedure.

    BEGIN
      send_mail(p_to        => '[email protected]',
                p_from      => '[email protected]',
                p_message   => 'Isso é apenas um Olá Mundo.',
                p_smtp_host => 'smtp.nsa.com');
    END;
    /

EDITED:

The only way to call external programs/processes is by the package:

dbms_scheduler, whose documentation is specified in this link.

  • grateful for the attention, for UTL_SMTP I know it is possible, but I would like to use a call via LINUX.

  • Okay, I’ll read the documentation.

  • 1

    Using the simple (UTL_SMTP) seems to me to be the best solution than the LINUX command.

  • @Motta, it is possible but not feasible. Depending on the version I suggest you also look at whether the UTL_MAIL is available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.