Send Emails from PL/SQL

1.要想从DB Server发邮件,首先得确保DB Server已经 启用了SMTP(Simple Mail Transfer Protocol)服务。检查是否启动SMTP的方法
telnet server.domain.com 25
(25是SMTP的默认端口)

2.PL/SQL to send email sample code:
DECLARE
   lc_from_email_id   VARCHAR2 (100);
   lc_mailhost        VARCHAR2 (100)      := 'abc.com';
   lc_connection      UTL_SMTP.connection;
   v_mail_sub         VARCHAR2 (200)      := 'Hello';
   v_mail_body        VARCHAR2 (1000)     := 'This is the mail body';
   v_from_email       VARCHAR2 (100)      := '[email protected]';
   v_to_email         VARCHAR2 (100)      := '[email protected]';
BEGIN
   lc_connection := UTL_SMTP.open_connection (lc_mailhost, 25);
   UTL_SMTP.helo (lc_connection, lc_mailhost);
   UTL_SMTP.mail (lc_connection, v_from_email);
   UTL_SMTP.rcpt (lc_connection, v_to_email);
   UTL_SMTP.open_data (lc_connection);
   UTL_SMTP.write_data (lc_connection, 'Subject' || ':' || v_mail_sub || ' ' || UTL_TCP.crlf);
   UTL_SMTP.write_data (lc_connection, UTL_TCP.crlf || v_mail_body || UTL_TCP.crlf);
   UTL_SMTP.close_data (lc_connection);
   UTL_SMTP.quit (lc_connection);
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Mail not sent');
END;


Send Emails from PL/SQL


ps:可以通过下边的Query来获取SMTP Server Name

select fscpv.parameter_value smtp_server_name
from   fnd_svc_comp_params_tl fscpt
,      fnd_svc_comp_param_vals fscpv
,      fnd_svc_components fsc
where  fscpt.parameter_id = fscpv.parameter_id
and    fscpv.component_id = fsc.component_id
and    fscpt.display_name = 'Outbound Server Name'
and    fsc.component_name = 'Workflow Notification Mailer';


你可能感兴趣的:(pl/sql)