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. fabric 安装及使用

    官网地址 1.安装 pip install fabric 依赖 Paramiko .PyCrypto库 以下依赖肯能要手动安装 #安装 pycrypto 密码库pip install pycrypto ...

  2. vsts

     首先要搞清楚啥是VSTS,这对于我们安装配置有基础作用.看看这张组织结构图就一目了然了.Visual Studio Team Suite就是我们常说的VS.NET 2005开发环境,安装包3G左右的 ...

  3. 第一个关于ajax的代码

    昨天由于需要,写了第一个需要ajax的程序,之前只是看过相关介绍,没想到这么有用,记录一下,如有错误,还希望大家提出$(document).ready(function () {//获取url中名字为 ...

  4. RDLC报表系列(二) 行分组

    接上一篇文章的内容,今天来说的是行分组.还是打开demo1.rdlc界面,拖入一个文本框和表 1.在表中随便选择一个字段,不然在添加行组的时候不会自动提示.我这里是选择的Dept 2.在下面的行组中右 ...

  5. Marshal 类的内存操作的一般功能

    Marshal类 提供了一个方法集,这些方法用于分配非托管内存.复制非托管内存块.将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法. 命名空间:System.Runtim ...

  6. 安装gVim

    从Vim官网下载其安装包,安装并首次运行后,开启控制台并执行如下命令: %HOMEDRIVE% cd %HOMEPATH% mkdir vimfiles cd vimfiles mkdir backu ...

  7. PLSQL Developer建表时注释(COMMENT)中文乱码的解决方案(Windows)

    简单的让你无法想象! 处理方法:在环境变量中新增系统变量 以下变量值对: 变量名:NLS_LANG变量值:AMERICAN_AMERICA.ZHS16GBK 好了

  8. smarty的简单介绍

    我们可以看到,smarty的程序部分实际就是符合php语言规范的一组代码,我们依次来解释一下:1./**/语句: 包含的部分为程序篇头注释.主要的内容应该为对程序的作用,版权与作者及编写时间做一个简单 ...

  9. SQL Server 空间监测

    数据库文件型: select * from sys.dm_db_file_space_usage;      go                                           ...

  10. RoHS认证简介

    RoHS认证是<电气.电子设备中限制使用某些有害物质指令>(The restriction of the use of certain hazardous substances in el ...