Send Emails from PL/SQL .
2013-07-09 12:14
260 查看
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:
[sql]
view plaincopyprint?
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) := 'ptian@xxx.com';
v_to_email VARCHAR2 (100) := 'ptian@xxx.com';
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;
ps:可以通过下边的Query来获取SMTP Server Name
[sql]
view plaincopyprint?
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';
telnet server.domain.com 25
(25是SMTP的默认端口)
2.PL/SQL to send email sample code:
[sql]
view plaincopyprint?
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) := 'ptian@xxx.com';
v_to_email VARCHAR2 (100) := 'ptian@xxx.com';
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;
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) := 'ptian@xxx.com'; v_to_email VARCHAR2 (100) := 'ptian@xxx.com'; 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;
ps:可以通过下边的Query来获取SMTP Server Name
[sql]
view plaincopyprint?
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';
相关文章推荐
- Send Emails from PL/SQL
- 在PL/SQL中使用“select * from 表名”返回的结果集是无序的
- ORACLE SEND MAIL WITH PL/SQL
- PL/SQL Developer快速输入select * from等语句快捷键设置
- PL/Sql不能用select * INTO t_s_userbak from t_s_user
- Invoking Webservice from PL/SQL (UTL_DBWS&UTL_HTTP)
- pl/sql developer快速输入select * from
- Quick way to send emails from PeopleCode
- pl/sql developer快速输入select * from
- PL/SQL如何快速打出select * from 记住登陆密码
- Performing SQL Operations from PL/SQL
- C# Retrieving Associative Arrays from PL/SQL Code
- Invoking Webservice from PL/SQL (UTL_DBWS&UTL_HTTP)
- Beginning PL/SQL: From Novice to Professional
- 摘录一段《Mastoring Oracle SQL》——PL/SQL Calling Stored Functions from Queries
- SQL SERVER – 2008 – Configure Database Mail – Send Email From SQL Database
- 解决 调PL/SQL存储过程报 trailing null missing from STR bind value 的问题
- How To Load CLOB Data from a File into a CLOB column using PL/SQL
- (转)FTP From PL/SQL
- Insert BLOB && CLOB from PL/SQL and JDBC