How to Send an Email Using UTL_SMTP with Authenticated Mail Server
来源:互联网 发布:手机日常生活必备软件 编辑:程序博客网 时间:2024/05/16 16:20
In this Document
APPLIES TO:
PL/SQL - Version 9.2.0.1 to 12.1.0.1 [Release 9.2 to 12.1]Information in this document applies to any platform.
***Checked for relevance on 07-Apr-2014***
GOAL
The UTL_SMTP package is designed for sending electronic mails (emails) over Simple Mail Transfer Protocol (SMTP) as specified by RFC821.
Some mail servers require a username and password to be supplied. The following error: 530 Authentication required , would occur if the username and password for the SMTP server is needed to use UTL_SMTP.
The sample code below shows how to include the username/password for the Mail server.
SOLUTION
Create or replace procedure testmail(fromm varchar2,too varchar2,sub varchar2,body varchar2,port number)
is
objConnection utl_smtp.connection;
username varchar2(20):= '<username>';
password varchar2(20):= '<password>';
vrData varchar2(32000);
BEGIN
objConnection := UTL_smtp.open_connection('<your domain server name>',port);
UTL_smtp.helo(objConnection, '<your domain name server>');
utl_smtp.command(objConnection, 'AUTH LOGIN');
utl_smtp.command(objConnection,UTL_RAW.CAST_TO_VARCHAR2(utl_encode.base64_encode(utl_raw.cast_to_raw(username))));
utl_smtp.command(objConnection,UTL_RAW.CAST_TO_VARCHAR2(utl_encode.base64_encode(utl_raw.cast_to_raw(password))));
UTL_smtp.mail(objConnection, fromm);
UTL_smtp.rcpt(objConnection, too);
UTL_smtp.open_data(objConnection);
/* ** Sending the header information */
UTL_smtp.write_data(objConnection, 'From: '||fromm || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'To: '||too || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'Subject: ' || sub || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'MIME-Version: ' || '1.0' || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'Content-Type: ' || 'text/html;');
UTL_smtp.write_data(objConnection, 'Content-Transfer-Encoding: ' || '"8Bit"' ||UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<HTML>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<BODY>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<FONT COLOR="red" FACE="Courier New">'||body||'</FONT>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'</BODY>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'</HTML>');
UTL_smtp.close_data(objConnection);
UTL_smtp.quit(objConnection);
EXCEPTION
WHEN UTL_smtp.transient_error OR UTL_smtp.permanent_error THEN
UTL_smtp.quit(objConnection);
dbms_output.put_line(sqlerrm);
WHEN OTHERS THEN
UTL_smtp.quit(objConnection);
dbms_output.put_line(sqlerrm);
END testmail;
/
is
objConnection utl_smtp.connection;
username varchar2(20):= '<username>';
password varchar2(20):= '<password>';
vrData varchar2(32000);
BEGIN
objConnection := UTL_smtp.open_connection('<your domain server name>',port);
UTL_smtp.helo(objConnection, '<your domain name server>');
utl_smtp.command(objConnection, 'AUTH LOGIN');
utl_smtp.command(objConnection,UTL_RAW.CAST_TO_VARCHAR2(utl_encode.base64_encode(utl_raw.cast_to_raw(username))));
utl_smtp.command(objConnection,UTL_RAW.CAST_TO_VARCHAR2(utl_encode.base64_encode(utl_raw.cast_to_raw(password))));
UTL_smtp.mail(objConnection, fromm);
UTL_smtp.rcpt(objConnection, too);
UTL_smtp.open_data(objConnection);
/* ** Sending the header information */
UTL_smtp.write_data(objConnection, 'From: '||fromm || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'To: '||too || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'Subject: ' || sub || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'MIME-Version: ' || '1.0' || UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection, 'Content-Type: ' || 'text/html;');
UTL_smtp.write_data(objConnection, 'Content-Transfer-Encoding: ' || '"8Bit"' ||UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF);
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<HTML>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<BODY>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'<FONT COLOR="red" FACE="Courier New">'||body||'</FONT>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'</BODY>');
UTL_smtp.write_data(objConnection,UTL_tcp.CRLF||'</HTML>');
UTL_smtp.close_data(objConnection);
UTL_smtp.quit(objConnection);
EXCEPTION
WHEN UTL_smtp.transient_error OR UTL_smtp.permanent_error THEN
UTL_smtp.quit(objConnection);
dbms_output.put_line(sqlerrm);
WHEN OTHERS THEN
UTL_smtp.quit(objConnection);
dbms_output.put_line(sqlerrm);
END testmail;
/
DECLARE
Vdate Varchar2(25);
BEGIN
Vdate := to_char(sysdate,'dd-mon-yyyy HH:MI:SS AM');
TESTMAIL('xxx.xxx@xxx.com', 'xxx.xxx@xxx.com', 'TESTMAIL','This is a UTL_SMTP-generated email at '|| Vdate,25);
END;
/
Vdate Varchar2(25);
BEGIN
Vdate := to_char(sysdate,'dd-mon-yyyy HH:MI:SS AM');
TESTMAIL('xxx.xxx@xxx.com', 'xxx.xxx@xxx.com', 'TESTMAIL','This is a UTL_SMTP-generated email at '|| Vdate,25);
END;
/
REFERENCES
NOTE:317301.1 - How to Test SMTP Authentication from a Telnet Session (for OES and OCS)NOTE:604763.1 - Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email.
NOTE:730746.1 - FAQ and Known Issues While Using UTL_SMTP and UTL_MAIL
NOTE:201639.1 - How to Use UTL_SMTP Package With a Mail Server That Needs a Username and Password?
0 0
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- using System.Web.Mail to send email
- How to send an email from oracle workflow process using an AdHocRole?
- How to send email using sqlserver
- How to make NAnt send an email using a real account
- how to send email
- Send an email using Telnet
- How do I authenticate to send an email
- How to send email via vbs using cdo
- Salesforce: How to Send Email with Default Template?
- Using exchange server to send email in Powershell
- Oracle send mail 套件utl_smtp
- android: how to send email
- How to send Email asynchronously
- How to send mail using any email account through Foxmail ? - Foxmail 6 漏洞,如何通过 Foxmail 用任意邮件账号发送邮件?
- Save an XML File to Database and Send an Email using XSLT
- Use Java Mail API to Send Email
- 查询在一张表不在另外一张表的记录
- Bootstrap的模态框中使用kindeditor无法编辑的问题
- POJ2418 Hardwood Species(字典树)
- 让Mac启动的时候自动启动mysql
- 第13周 项目6-4 文件的读取与读入
- How to Send an Email Using UTL_SMTP with Authenticated Mail Server
- android中getSystemService详解
- 大臣的旅费 解题报告
- ViewPager 工作机制
- 周期串
- vc++6.0中的大数问题
- 【网络安全】EAP协议
- [iOS_Dev] pop / push modal
- 内核模块加载错误 Makefile