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. SpriteKit中为何不要在update方法中测试碰撞

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 我们若要在游戏中做碰撞检测有2种办法,一是利用物理引擎,二是自 ...

  2. How to speed up Remote Desktop Connection in Win7

    run following command in DOS window: netsh interface tcp set global autotuninglevel=disabled or nets ...

  3. 多线程之Java线程阻塞与唤醒

    线程的阻塞和唤醒在多线程并发过程中是一个关键点,当线程数量达到很大的数量级时,并发可能带来很多隐蔽的问题.如何正确暂停一个线程,暂停后又如何在一个要求的时间点恢复,这些都需要仔细考虑的细节.在Java ...

  4. Android中Socket通信之TCP与UDP传输原理

    一.Socket通信简介 Android与服务器的通信方式主要有两种,一是Http通信,一是Socket通信.两者的最大差异在于,http连接使用的是"请求-响应方式",即在请求时 ...

  5. Error处理:Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack tra

    [2014-04-20 20:59:23 - MyDetectActivity] Dx  trouble writing output: already prepared [2014-04-20 20 ...

  6. Android的AdapterViewFlipper和Stackview-android学习之旅(三十)

    AdapterViewFlipper简介 AdapterViewFlipper继承了AdapterViewAnimater.每次只能显示一个组件,用showPrevious()和showNext()来 ...

  7. UNIX网络编程——处理服务器中大量的TIME_WAIT

    出现条件: 服务器主动关闭 短连接服务加剧 根据TCP协议定义的3次握手断开连接规定,发起socket主动关闭的一方 socket将进入TIME_WAIT状态,TIME_WAIT状态将持续2个MSL( ...

  8. Android 面向协议编程 体会优雅编程之旅

    Android中面向协议编程的深入浅出 http://blog.csdn.net/sk719887916/article/details skay编写 说起协议,现实生活中大家第一感觉会想到规则或者约 ...

  9. Dynamics CRM2013 去除界面顶部黄色的CRM For Outlook条框

    Dynamics CRM2013中每次打开系统页面上方都会有个黄条看着很是烦人,效果如下图 庆幸的是系统提供了关闭的开关,设置-管理-系统设置,把"设置CRM For Outlook消息是否 ...

  10. Cocos2D:塔防游戏制作之旅(五)

    打开HelloWorldLayer.h文件,添加以下实例变量(在@interface行的花括号之后): NSMutableArray *towerBases; 将HelloWorldLayer.m文件 ...