[ORACLE]UTL_SMTP发邮件
来源:互联网 发布:c语言中-76绝对值 编辑:程序博客网 时间:2024/05/16 15:51
--ORACLE发邮件declare SendorAddress VARCHAR2(50) := '3edcvf@163.com'; ReceiverAddress VARCHAR2(30) := '278676125@qq.com'; EmailServer VARCHAR2(30) := 'smtp.163.com'; Port NUMBER := 25; conn UTL_SMTP.CONNECTION; crlf VARCHAR2(2) := CHR(13) || CHR(10); mesg VARCHAR2(4000); mesg_body VARCHAR2(4000);BEGIN conn := utl_smtp.open_connection(EmailServer, Port); utl_smtp.helo(conn, EmailServer); UTL_SMTP.COMMAND(conn, 'AUTH LOGIN'); UTL_SMTP.COMMAND(conn, UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(UTL_RAW.CAST_TO_RAW('3edcvf')))); UTL_SMTP.COMMAND(conn, UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(UTL_RAW.CAST_TO_RAW('&pwd')))); utl_smtp.mail(conn, '<'||SendorAddress||'>'); utl_smtp.rcpt(conn, '<'||ReceiverAddress||'>'); mesg := 'Content-Type: text/plain; Charset=GB2312' || crlf || 'Date:' || TO_CHAR(SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf || 'From:' || SendorAddress || crlf || 'Subject: Test Mail From OracleDatabase' || crlf || 'To: ' || ReceiverAddress || crlf || 'Content-Type: text/plain; Charset=GB2312' || crlf || '' || crlf || '你好啊,cry' || crlf; utl_smtp.open_data(conn); utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(mesg)); utl_smtp.close_data(conn); --utl_smtp.data(conn, mesg); utl_smtp.quit(conn);exception when others then utl_smtp.quit(conn); raise;END;
注:支持中文,不支持附件! 需要在SYS权限下执行,否则可能会报下面的421 service not available错误.
遇到的2个错误:
1.ORA-29279: SMTP 永久性错误: 550 Invalid User
解决: utl_smtp.mail和utl_smtp.rcpt发送和接收的地址前后需要加上'<'和'>'
2. ORA-29278: SMTP 临时性错误: 421 service not available
解决:邮件服务器地址不对,这里要填SMTP服务器地址。163的邮箱填 'smtp.163.com'
3.SSL的SMTP服务器发送邮件,Oracle好像不支持
注:如做成存储过程,需要使用调用者权限,即加上AUTHID CURRENT_USER
所有异常CODE如下:
211
System status, or system help reply
214
Help message [Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user]
220
<domain>
Service ready
221
<domain>
Service closing transmission channel
250
Requested mail action okay, completed
251
User not local; forwards to <forward-path>
252
OK, pending messages for node <node>
started. Cannot VRFY
user (for example, info is not local), but takes message for this user and attempts delivery.
253
OK, <messages>
pending messages for node <node>
started
354
Start mail input; end with <CRLF.CRLF>
355
Octet-offset is the transaction offset
421
<domain>
Service not available, closing transmission channel (This can be a reply to any command if the service knows it must shut down.)
450
Requested mail action not taken: mailbox unavailable [for example, mailbox busy]
451
Requested action terminated: local error in processing
452
Requested action not taken: insufficient system storage
453
You have no mail.
454
TLS not available due to temporary reason. Encryption required for requested authentication mechanism.
458
Unable to queue messages for node <node>
459
Node <node>
not allowed: reason
500
Syntax error, command unrecognized (This may include errors such as command line too long.)
501
Syntax error in parameters or arguments
502
Command not implemented
503
Bad sequence of commands
504
Command parameter not implemented
521
<Machine>
does not accept mail.
530
Must issue a STARTTLS
command first. Encryption required for requested authentication mechanism.
534
Authentication mechanism is too weak.
538
Encryption required for requested authentication mechanism.
550
Requested action not taken: mailbox unavailable [for, mailbox not found, no access]
551
User not local; please try <forward-path>
552
Requested mail action terminated: exceeded storage allocation
553
Requested action not taken: mailbox name not allowed [for example, mailbox syntax incorrect]
554
Transaction failed
- [ORACLE]UTL_SMTP发邮件
- 利用Oracle的UTL_SMTP包发邮件设置抄送
- Oracle UTL_SMTP邮件发送
- oracle utl_smtp 邮件发送协议
- 利用oracle系统包UTL_SMTP发送邮件
- 别人家的oracle utl_smtp 发送邮件
- 利用Oracle数据库的UTL_SMTP发送HTML 邮件
- 利用UTL_SMTP发送邮件
- Oracle 发邮件
- 使用oracle发邮件
- oracle 发邮件功能
- 利用Oracle的utl_smtp 发送邮件(公网邮件和服务器)
- 使用UTL_SMTP包发送邮件
- 在 Oracle中使用UTL_SMTP 进行邮件发送的例子代码
- Oracle 11g 环境下,利用utl_smtp创建发送邮件的存储过程
- 用Oracle自动发邮件
- Oracle send mail 套件utl_smtp
- UTL_SMTP发送邮件,防中文乱码处理!
- hive介绍
- 拷贝构造函数与赋值构造函数(operator=)的区别
- Android APK反编译详解(附图)
- hive的数据类型和数据模型
- 【Nginx】基本配置入门
- [ORACLE]UTL_SMTP发邮件
- ThinkPHP 中 模型 getField 方法使用
- JS实现 页面提交防刷新等待提示
- Windows Phone 8 , IOS, Android手势操作优先级对比
- C++复制构造函数和赋值符的区别
- 我有个梦想
- 网络安全热门资料 精品工具
- Java 深拷贝和浅拷贝
- RFC知识和RFC debug技巧。。