Exzilla.net
Contact
Home -> Articles -> Internet Packages -> UTL_SMTP
 
Features
Forums
Files
Blogs
Howto: Overview of internet Packages in Oracle Database -- UTL_SMTP
Aug 1, 2001
Tyranno
Author's Bio | E-Mail
Copyright (C) 2001 exzilla.net

 

HOWTO: Overview of Internet Packages in Oracle Database -- UTL_SMTP

Prerequistires:

Oracle8i or later

Purpose:

UTL_SMTP package ถูกออกแบบเพื่อให้ผู้พัฒนา PL/SQL program สามารถส่ง e-mail โดยใช้ผ่าน Simple Mail Transfer Protocol (SMTP)

Step-by-Step Example:

Create sendmail procedure

create or replace procedure fuju_send_mail (
sender      IN VARCHAR2, 
recipient   IN VARCHAR2, 
message     IN VARCHAR2)
IS 
  mailhost VARCHAR2(30) := 'mail.exzilla.net'; 
  mail_conn utl_smtp.connection; 
BEGIN 
 mail_conn :=  utl_smtp.open_connection(mailhost, 25); 
  utl_smtp.helo(mail_conn, mailhost); 
  utl_smtp.mail(mail_conn, sender);
  utl_smtp.rcpt(mail_conn, recipient); 
  utl_smtp.data(mail_conn, message); 
  utl_smtp.quit(mail_conn); 
END; 

		   	  		

 

Testing sendmail procedure

SQL> set serveroutput on
SQL> l
  1  create or replace procedure fuju_send_mail (
  2  sender      IN VARCHAR2,
  3  recipient   IN VARCHAR2,
  4  message     IN VARCHAR2)
  5  IS
  6    mailhost VARCHAR2(30) := 'mail.exzilla.net';
  7    mail_conn utl_smtp.connection;
  8  BEGIN
  9   mail_conn :=  utl_smtp.open_connection(mailhost, 25);
 10    utl_smtp.helo(mail_conn, mailhost);
 11    utl_smtp.mail(mail_conn, sender);
 12    utl_smtp.rcpt(mail_conn, recipient);
 13    utl_smtp.data(mail_conn, message);
 14    utl_smtp.quit(mail_conn);
 15* END;
SQL> 
SQL> exec fuju_send_mail('fuju@exzilla.net','o9i','Hi from fuju ');

PL/SQL procedure successfully completed.

SQL> exit
$ 
you have mail in /var/mail/o9i
$ id
uid=127(o9i) gid=100(dba)
$ 
$ mail
From fuju@exzilla.net Mon Jun 25 10:15:36 2001
Date: Mon, 25 Jun 2001 10:15:36 -0700 (GMT)
From: fuju@exzilla.net
Message-Id: <200106251715.KAA10530@mail.exzilla.net>
Content-Length: 29

Hi from fuju 

? 
$ 
		   	  		

 

Note:

UTL_SMTP provides API for SMTP communication as specified in RFC821.

Complete Sample code:

References:

Oracle9i Supplied PL/SQL Packages and Types Reference Release 1 (9.0.1)

Part Number A89852-02

You can download from http://otn.oracle.com/

More Information:

Oracle9i Supplied PL/SQL Packages and Types Reference Release 1 (9.0.1)

Part Number A89852-02 You can download from http://otn.oracle.com/

RFC documents are "Request for Comments" documents that describe proposed standards for public review on the Internet.

For the actual RFC documents, please refer to: http://www.ietf.org/rfc/

Keywords:

UTL_SMTP packages , mail client , smtp protocol , PL/SQL

 
 
{exzilla.net -- e-development QuickStart --}



Copyright (c) 2001-2009 - Exzilla.net -  All Rights Reserved.
Contact Us | Privacy Policy | Terms & Conditions