Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1996317
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 17:45:14


  CREATE OR REPLACE PROCEDURE "SYS"."SEND_MAIL"
  (
  pSender VARCHAR2,
  pRecipient VARCHAR2,
  pSubject VARCHAR2,
  pMessage VARCHAR2)
  IS
  
  mailhost CONSTANT VARCHAR2(30) := 'YOUR MAIL SYSTEM IP OR FQDN';
  crlf CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
  mesg VARCHAR2(1000);
  mail_conn UTL_SMTP.CONNECTION;
  
  BEGIN
  mail_conn := utl_smtp.open_connection(mailhost, 25);
  mesg := 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf || 'From: <'|| pSender ||'>' || crlf || 'Subject: '|| pSubject || crlf || 'To: '||pRecipient || crlf || '' || crlf || pMessage;
  utl_smtp.helo(mail_conn, mailhost);
  utl_smtp.mail(mail_conn, pSender);
  utl_smtp.rcpt(mail_conn, pRecipient);
  utl_smtp.data(mail_conn, mesg);
  utl_smtp.quit(mail_conn);
  
  END send_mail;
  
  使用范例
  
  SQL> desc send_mail
  PROCEDURE send_mail
  Argument Name Type In/Out Default?
  ------------------------------ ----------------------- ------ --------
  PSENDER VARCHAR2 IN
  PRECIPIENT VARCHAR2 IN
  PSUBJECT VARCHAR2 IN
  PMESSAGE VARCHAR2 IN
  
  SQL> exec send_mail('apple','chu@odba.idv.tw','Test','hello')
  
  PL/SQL procedure successfully completed.
  
  上面的范例是利用远端的mail service来寄信,简单又容易实做!!
【责编:admin】

--------------------next---------------------

阅读(224) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~