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; 
/

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; 
/

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?

How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)的更多相关文章

  1. How to Send an Email Using UTL_SMTP with Authenticated Mail Server

    In this Document   Goal   Solution   References APPLIES TO: PL/SQL - Version 9.2.0.1 to 12.1.0.1 [Re ...

  2. Send an email with format which is stored in a word document

    1. Add a dll reference: Microsoft.Office.Interop.Word.dll 2. Add the following usings using Word = M ...

  3. [转]How To Send Transactional Email In A NodeJS App Using The Mailgun API

    https://www.npmjs.com/package/mailgun-js 本文转自:https://www.mailgun.com/blog/how-to-send-transactional ...

  4. android Email总结文档

    目录:src\com.android.email.activity 一. Welcome.java 根据AndroidManifest.xml可知该文件为程序入口文件: 加载该文件时,查询数据库账户列 ...

  5. ORACLE的Dead Connection Detection浅析

    在复杂的应用环境下,我们经常会遇到一些非常复杂并且有意思的问题,例如,我们会遇到网络异常(网络掉包.无线网络断线).客户端程序异常(例如应用程序崩溃Crash).操作系统蓝屏.客户端电脑掉电.死机重启 ...

  6. Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email

    Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email. (文档 I ...

  7. 5 Ways to Send Email From Linux Command Line

    https://tecadmin.net/ways-to-send-email-from-linux-command-line/ We all know the importance of email ...

  8. 11i - 12 How To Set Email Style Preference For All Users At Once?

    (文档 ID 578574.1) In this Document   Goal   Solution   Workflow Information Center, Diagnostics, & ...

  9. How to Verify Email Address

    http://www.ruanyifeng.com/blog/2017/06/smtp-protocol.html  如何验证 Email 地址:SMTP 协议入门教程 https://en.wiki ...

随机推荐

  1. Android工程师面试准备知识点

    听+7哥说,把下面的全弄懂,面试必过,所以我就试着去把所有题目补充了一下,各位能耐的网友们,如果有吐槽或者补充的尽管给我留言,在这里谢过大家了. 1.   android的多线程如何通信 答:Andr ...

  2. 开源企业IM-免费企业即时通讯-ENTBOOST V2014.180 Linux版本号正式公布

    ENTBOOST,VERSION 2014.180 Linux版本号公布,主要添加企业IM应用集成功能,完好安卓SDK功能及部分BUG修正: 7/1(明天)公布Windows版本号,敬请关注! ENT ...

  3. Cocos2d-x Render-NewCulling

    .cpp layout->setBackGroundImageScale9Enabled(true); layout->setBackGroundImage("green_edi ...

  4. 用cssText属性批量操作样式

    给一个HTML元素设置css属性,如 var head= document.getElementById("head"); head.style.width = "200 ...

  5. 搭建MyBatis框架

    一.开发环境 1.JDK 1.6.0_22 2.MyEclipse 10.7.1 3.Oracle_10g_10.2.0.4 注:各软件版本不是必须的,正常任意版本都行,文件较大就不附上下载地址了,推 ...

  6. SQL高级查询的练习题

    Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...

  7. Lucene学习之CURD

    创建索引 Lucene在进行创建索引时,根据前面一篇博客,已经讲完了大体的流程,这里再简单说下: Directory directory = FSDirectory.open("/tmp/t ...

  8. js数组(一)

    一.创建数组两种方法: 1Array构造 var colors = new Array();2.字面量表示什么事字面量,如 var colors = ["red","gr ...

  9. codeforces 702E Analysis of Pathes in Functional Graph 倍增

    题目链接 给一个图, 然后给出每条边的权值和一个k值. 让你求出从每个点出发, 走k次能获得的边权的和以及边权的最小值. 用倍增的思想, 求出每个点走一次能到达的点, 权值和以及最小值, 走两次..四 ...

  10. Delphi RichEdit的内容保存为图片

    uses RichEdit; {将RichEdit1的内容保存为图片,此函数也适合于RxRichEdit,即RichEdit: TRxRichEdit}procedure RichEditToCanv ...