In this Document

  Goal
  Solution
  References

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的更多相关文章

  1. How to Send an Email Using UTL_SMTP with Authenticated Mail Server. (文档 ID 885522.1)

    APPLIES TO: PL/SQL - Version 9.2.0.1 to 12.1.0.1 [Release 9.2 to 12.1]Information in this document a ...

  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. 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 ...

  5. How to Verify Email Address

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

  6. roundup配置

    原因:我需要一个简单的issue tracker why roundup: python,简单 找了半天的文档,找不到文档,只能自己慢慢试,试到现在,可以打开tracker页面,用户注册的时候可以发邮 ...

  7. 关于多域名EXCHANGE如何设置PTR的问题

    找了很多网页, 有效的是MX可以设置不同的域名,但PTR只设置一个即可... 如果设置为一个IP为两个PTR,则在进行测试时,会发生DNS ROBBINS,即一次找这个,一次找那个. 切记. .... ...

  8. [源码分享] HIVE表数据量统计&邮件

    概要: 计算HIVE BI库下每天数据表总大小及增量 输出: 总大小:xxxG 日同比新增数据量:xxxG 周同比新增数据量:xxxG 月同比新增数据量:xxxG 总表数:xxx 日新增表数:xxx ...

  9. 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 ...

随机推荐

  1. EXCEL技能之数据去重

    本篇不属于技术类博文,只是想找个地方记录而已,既然是我的博客嘛,那就自己想写什么就写什么了. CRM中有个EXCEL数据导入功能,几千条数据导入CRM后去重,那是死的心都有的.往回想想EXCEL是否有 ...

  2. 安卓开发过程中空指针的问题Java.lang.NullPointerException

    最近做一个新闻客户端的应用,经常出现空指针的问题,我想一方面可能是自己水平有限,二是开发过程中有一些遗漏的地方.一般情况下新手出现空指针的概率较高.下面来总结一下经常出现的问题. 1.所谓的指针,就是 ...

  3. 即时通讯软件openfire+spark+smack

    所以我基本上分为三篇文章来介绍此类软件的开发: 第一篇是关于XMPP 协议是啥,IM 是啥以及一个比较有名的开源实现,该开源实现包括三个部分(Spark.Smack和Openfire): 第二篇讲如何 ...

  4. MySQL 存储过程探秘

    关于存储过程的优点,本文不再阐述.这里只是对创建存储过程时可能遇到的问题做一下简单的分析. 必备基础 这里说的基础,是相关于如何创建一个存储过程的. DELIMITER:分隔符,定界符. 作用就是:作 ...

  5. javascript之页面打印

    WebBrowser组件是IE内置的浏览器控件,使用时,首先要在<body>标签的下面用<object>...</object>标记声明WebBrowser组件,代 ...

  6. ubuntu安装水星MW150US无线网卡8188eu驱动

    买了一个无线网卡插在ubuntu系统的电脑上,却不能识别出来.lsusb,可以看到下面的结果: Bus 002 Device 002: ID 0bda:8179 Realtek Semiconduct ...

  7. GDAL1.11版本对SHP文件索引加速测试

    GDAL库中对于矢量数据的读取中可以设置一些过滤器来对矢量图形进行筛选,对于Shapefile格式来说,如果数据量太大,设置这个过滤器时间慢的简直无法忍受.好在GDAL1.10版本开始支持读取Shap ...

  8. Java进阶(三十四)Integer与int的种种比较你知道多少?

    Java进阶(三十四)Integer与int的种种比较你知道多少? 前言 如果面试官问Integer与int的区别:估计大多数人只会说到两点:Ingeter是int的包装类,注意是一个类:int的初值 ...

  9. linux的wc -l 命令统计文件少一行(一般是windows文件)

    先简单介绍 wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出 格式:wc file 命令参数: -c 统计Bytes数(字节数),并显示文件名 -l 统 ...

  10. 如何在Cocos2D游戏中实现A*寻路算法(五)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...