p_message IN VARCHAR2,
p_subject IN VARCHAR2 :='Oracle Perf Report ' || TO_CHAR (SYSDATE, 'yyyy-mm-dd hh24:mi:ss' ),
p_sender IN VARCHAR2 DEFAULT 'xx@xx.com')--发送
IS
v_mailhost VARCHAR2 (30) := 'smtp.xx.com'; --SMTP服务器地址
mail_conn UTL_SMTP.connection;
msg VARCHAR2 (4000);
p_user VARCHAR2 (30) := 'xx@xx.com';
--登录SMTP服务器的用户名
p_pass VARCHAR2 (30) := 'xxx'; --登录SMTP服务器的密码
BEGIN
/* 创建要发送的邮件内容 注意报头信息和邮件正文之间要空一行 */
msg :='Content-Type:text/plain;Charset=GB2312'|| UTL_TCP.crlf ||'Date:'|| TO_CHAR (SYSDATE, 'dd mon yy hh24:mi:ss')
|| UTL_TCP.crlf|| 'From: '
|| p_sender|| '<'|| p_sender|| '>'|| UTL_TCP.crlf
|| 'To: '|| p_recipient|| '<'|| p_recipient|| '>'||'Content-Type: text/plain; Charset=GB2312'
|| UTL_TCP.crlf|| 'Subject: '|| p_subject
|| UTL_TCP.crlf|| UTL_TCP.crlf|| p_message
;
mail_conn := UTL_SMTP.open_connection (v_mailhost, 25);
UTL_SMTP.helo (mail_conn, v_mailhost);
/* smtp服务器登录校验 */
UTL_SMTP.command (mail_conn, 'AUTH LOGIN');
UTL_SMTP.command
(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (p_user)))
);
UTL_SMTP.command(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (p_pass) )
));
UTL_SMTP.mail (mail_conn, p_sender);
UTL_SMTP.rcpt (mail_conn, p_recipient);
/* 发送数据 */
--dbms_output.put_line(msg);
-------1------ UTL_SMTP.DATA (mail_conn, msg);
-------2------ UTL_SMTP.write_raw_data(mail_conn,utl_raw.cast_to_raw(msg));
UTL_SMTP.quit (mail_conn);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
NULL;
END send_mail;
问题1:
用1的部分,可以发送邮件,但是内容如果为中文则为乱码
用2的部分,不可以发送邮件,
错误:ORA-29277: SMTP 操作无效
----- PL/SQL Call Stack -----
object line object
handle number name
0954D6C8 41 procedure SEND_MAIL
090B47B8 1 anonymous block
问题2:
怎么修改上述错误?
10 个解决方案
#1
顶下了
因为是要自爱orcale中把一些数据的处理结果通知给用户,所以。。
因为是要自爱orcale中把一些数据的处理结果通知给用户,所以。。
#2
乱码问题需要处理一下,你看看这个帖子吧,很好的
http://topic.csdn.net/u/20080606/11/bb4c6d4c-cb72-498a-b909-386933812b5c.html
http://topic.csdn.net/u/20080606/11/bb4c6d4c-cb72-498a-b909-386933812b5c.html
#3
我也学习学习
#4
我就想就我的这个问题 进行解决
谢谢大家
谢谢大家
#5
UTL_SMTP.DATA (mail_conn, msg);
#6
各位帮忙看看了,谢谢了
^_^
^_^
#7
没有兄弟帮忙哦
#8
UTL_SMTP.DATA (mail_conn, msg);
#9
UTL_SMTP.write_raw_data 之前要先OPEN_DATA,你这样做肯定是有问题的。
具体的步骤参考:
utl_smtp.open_data(mail_conn);
send_header(mail_conn,'From', '"Sender" <'||sender||'>');
send_header(mail_conn,'To', '"Recipient" <'||recipient||'>');
send_header(mail_conn,'Subject', subject);
utl_smtp.write_data(mail_conn, utl_tcp.CRLF||message); //注意需要在这里把你的message Convert一下 eg:UTL_SMTP.write_raw_data(mail_conn,utl_raw.cast_to_raw(convert(msg,'ZHS16GBK'));
utl_smtp.close_data(mail_conn);
UTL_SMTP.quit (mail_conn);
具体的步骤参考:
utl_smtp.open_data(mail_conn);
send_header(mail_conn,'From', '"Sender" <'||sender||'>');
send_header(mail_conn,'To', '"Recipient" <'||recipient||'>');
send_header(mail_conn,'Subject', subject);
utl_smtp.write_data(mail_conn, utl_tcp.CRLF||message); //注意需要在这里把你的message Convert一下 eg:UTL_SMTP.write_raw_data(mail_conn,utl_raw.cast_to_raw(convert(msg,'ZHS16GBK'));
utl_smtp.close_data(mail_conn);
UTL_SMTP.quit (mail_conn);
#10
呵呵 虽然没解决问题 还是谢谢大家了哦 jf
#1
顶下了
因为是要自爱orcale中把一些数据的处理结果通知给用户,所以。。
因为是要自爱orcale中把一些数据的处理结果通知给用户,所以。。
#2
乱码问题需要处理一下,你看看这个帖子吧,很好的
http://topic.csdn.net/u/20080606/11/bb4c6d4c-cb72-498a-b909-386933812b5c.html
http://topic.csdn.net/u/20080606/11/bb4c6d4c-cb72-498a-b909-386933812b5c.html
#3
我也学习学习
#4
我就想就我的这个问题 进行解决
谢谢大家
谢谢大家
#5
UTL_SMTP.DATA (mail_conn, msg);
#6
各位帮忙看看了,谢谢了
^_^
^_^
#7
没有兄弟帮忙哦
#8
UTL_SMTP.DATA (mail_conn, msg);
#9
UTL_SMTP.write_raw_data 之前要先OPEN_DATA,你这样做肯定是有问题的。
具体的步骤参考:
utl_smtp.open_data(mail_conn);
send_header(mail_conn,'From', '"Sender" <'||sender||'>');
send_header(mail_conn,'To', '"Recipient" <'||recipient||'>');
send_header(mail_conn,'Subject', subject);
utl_smtp.write_data(mail_conn, utl_tcp.CRLF||message); //注意需要在这里把你的message Convert一下 eg:UTL_SMTP.write_raw_data(mail_conn,utl_raw.cast_to_raw(convert(msg,'ZHS16GBK'));
utl_smtp.close_data(mail_conn);
UTL_SMTP.quit (mail_conn);
具体的步骤参考:
utl_smtp.open_data(mail_conn);
send_header(mail_conn,'From', '"Sender" <'||sender||'>');
send_header(mail_conn,'To', '"Recipient" <'||recipient||'>');
send_header(mail_conn,'Subject', subject);
utl_smtp.write_data(mail_conn, utl_tcp.CRLF||message); //注意需要在这里把你的message Convert一下 eg:UTL_SMTP.write_raw_data(mail_conn,utl_raw.cast_to_raw(convert(msg,'ZHS16GBK'));
utl_smtp.close_data(mail_conn);
UTL_SMTP.quit (mail_conn);
#10
呵呵 虽然没解决问题 还是谢谢大家了哦 jf