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. Android4.0中蓝牙适配器state machine(状态机)的分析

    今天晓东和大家来一起看一下Android4.0中蓝牙适配器(Bluetooth Adapter)的状态机变化的过程.首先,我们需要了解一下,蓝牙适配器究竟有哪些状态,从代码可以清晰地看到(framew ...

  2. cocos2d-x 学习笔记一(概述)

    1.游戏-可控制的动画-连续的静态图像 2.关键帧驱动游戏 3.事件驱动型游戏 4.cocos2d-x 1.0 opengl-es 1.0;cocos2d-x 2.x opengl-es 2.0;co ...

  3. malloc用法

    malloc用法三部曲:(#include<stdlib.h>下的库函数) 1.malloc eg.ps=(char*)malloc(sizeof(char)*20)的意思是,动态分配空间 ...

  4. 畅通project(杭电1863)

    畅通project Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. Activity(三)

    常用控件 EditView.TextView.Button 设置layout,在fragment_main.xml配置控件 配置可编辑文本控件factorOne.factorTwo,显示文本控件sym ...

  6. SQL Server DML(UPDATE、INSERT、DELETE)常见用法(一)

    1.引言 T-SQL(Transact Structured Query Language)是标准的SQL的扩展,是程序和SQL Server沟通的主要语言. T-SQL语言主要由以下几部分组成: 数 ...

  7. 自定义按照index和key访问的List

    List<T>用起来比较方便,但是有时候要按照Index来访问List中的对象有些繁琐,所以想是不是扩展一下,既能按照Index来访问,又能按照Key访问. 实现方法: public cl ...

  8. js 正则表达式验证 整理

    1.验证首字符是英文字母: var str="123"; var reg=/^[a-zA-Z]/; if(!reg.test(str)){ alert(str+"应以字母 ...

  9. 在Google map图上做标记,并把标记相连接

    <!DOCTYPE html> <html> <head> <title>GeoLocation</title> <meta name ...

  10. PHP获取真实的网络IP

    function get_client_ip() { $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_CLIENT_IP']) & ...