Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How can I automatically send an email

Re: How can I automatically send an email

From: Mladen Gogala <mgogala_at_yahoo.com>
Date: Sun, 04 Apr 1999 02:22:33 GMT
Message-ID: <7e6id4$l30$1@nnrp1.dejanews.com>


In article <37066D2A.3B11D038_at_nl.origin-it.com>,   Joep Hendrix <joep.hendrix_at_nl.origin-it.com> wrote:
> Hi everyone,
>
> I would like to automatically send an email triggered by a certain
> change in the database (UNIX and/or NT server operating system).
>
> Thanks in advance,
>
> Joep Hendrix
>
>

Joep, For sending email from Oracle8, you need to write an external procedure and then use dbms_alert to trigger it automatically. Here is a version of an external procedure that I've developed on Intel Solaris 2.6:


int

email (char *address, int addrlen, short addrind,
       char *subject, int subjlen, short subjind,
       char *message, int msglen, short msgind)
{
  char *email[3] =		/* mail command to exec */
  {"mail", NULL, NULL};

  int pfd[2];
  pid_t pid = 0;
  int status = 0;
  int wrtn = 0;

  char buffer[BUFFSIZE];	/* Message buffer to format the message. This
                                   avoids multiple calls to 'write' system
                                   service. This is always a performance
                                   improvement, at the expense of somewhat
                                   larger address space.
                                */

/*

   Check the arguments and fix them if they are NULL. */
  if ((addrind == OCI_IND_NOTNULL) && (addrlen > 0))     email[1] = address;
  else
    return (-1);
  if ((subjind == OCI_IND_NULL) || (subjlen <= 0))     subject = " ";
  if ((msgind == OCI_IND_NULL) || (msglen <= 0))     message = " ";

/* Format the message */

  sprintf (buffer, "Subject:%s\n%s", subject, message);

/*

   Open a pipe and redirect system input to the pipe. */
  pipe (pfd);
  close (0);
  dup (pfd[0]);

  if ((pid = fork ()))
    {
/*

   Parent process writes the message to the pipe,closes the pipe    and waits for the child process to complete. */

      wrtn = write (pfd[1], buffer, strlen (buffer) + 1);
      close (pfd[1]);
      if (wrtn == -1)
	return (errno);
      waitpid (pid, &status);
      return (status);

    }
  else
    {
/*

   Child process executes mailer and exits. */

      status = execvp (MAILER, email);
      if (status < 0)
	return (errno);

    }

}


Mladen Gogala

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Sat Apr 03 1999 - 21:22:33 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US