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. Java进阶(四十四)线程与进程的特征及区别

    线程与进程的特征及区别 定义及特征 进程   指在系统中能独立运行并作为资源分配的基本单位,它是由一组机器指令.数据和堆栈等组成的,是一个能独立运行的活动实体. 进程的特征: 1.动态性:进程的实质是 ...

  2. Web服务,XFire的一个例子

    Web服务优点 互操作性:实现不同系统间的相互调用(语言无关.平台无关) Web服务是什么 Web 服务是一类应用程序,是能够用编程的方法通过Web调用来实现某个功能的应用程序 Web服务的体系结构 ...

  3. IMDG中的陷阱和问题

    陷阱 使用cache API时,一个最重要的问题就是潜在的数据加载.因为IMDG提供的分布式集合也都是实现的JDK的Map.Set等接口,以JDK的Map为例,它接口规定put和remove返回被替换 ...

  4. Spark调度模式-FIFO和FAIR

    Spark中的调度模式主要有两种:FIFO和FAIR.默认情况下Spark的调度模式是FIFO(先进先出),谁先提交谁先执行,后面的任务需要等待前面的任务执行.而FAIR(公平调度)模式支持在调度池中 ...

  5. Swift中集合类型indexOf(Element)提示错误的解决办法

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 初学Swift,会遇到一些潜在的小问题,比如我们在某个集合对象 ...

  6. JAVA之旅(三十三)——TCP传输,互相(伤害)传输,复制文件,上传图片,多并发上传,多并发登录

    JAVA之旅(三十三)--TCP传输,互相(伤害)传输,复制文件,上传图片,多并发上传,多并发登录 我们继续网络编程 一.TCP 说完UDP,我们就来说下我们应该重点掌握的TCP了 TCP传输 Soc ...

  7. T-SQL中的APPLY用法(半翻译)

    本文接上文:T-SQL 中的CROSS JOIN用法(半翻译) 同样可用于微软认证70-461: Querying Microsoft SQL Server 2012考试的学习中. --------- ...

  8. UNIX网络编程——进程间通信概述

    一.顺序程序与并发程序特征 顺序程序特征 顺序性封闭性:(运行环境的封闭性)确定性可再现性 并发程序特征 共享性并发性随机性 二.进程互斥 1.由于各进程要求共享资源,而且有些资源需要互斥使用,因此各 ...

  9. 【一天一道LeetCode】#232. Implement Queue using Stacks

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Impleme ...

  10. Java-IO之ByteArrayInputStream

    ByteArrayInputStream是字节数组输入流,继承于InputStream.它包含了一个内部缓冲区,该缓冲区包含从流中读取的字节,其实内部缓冲区就是一个字节数组,而ByteArrayInp ...