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. C#字符串处理 及字符串格式化

    本文来自:http://www.cnblogs.com/xuerongli/archive/2013/03/23/2976669.html string字符串是char的集合,而char是Unicod ...

  2. [AS3]as3与JS的交互(AS3调用JS)实例说明

    一,AS3 vs JavaScript (1)AS3调用JS 函数: ExternalInterface.(functionName:, arguments): //AS3 Code 属性: 同上,通 ...

  3. 使用HTML5/CSS3制作便签贴

    利用HTML5/CSS3,仅用5步就可以制作便签贴效果的HTML页面,效果图如下: (注:图里的文字纯属杜撰,搞笑目的,如有雷同,纯属巧合,谢谢!) 注:该效果可以在Safari, Chrome,Fi ...

  4. 【线段树求逆序数】【HDU1394】Minimum Inversion Number

    题目大意: 随机给你全排列中的一个,但不断的把第一个数丢到最后去,重复N次,形成了N个排列,问你这N个排列中逆序数最小为多少 做法: 逆序数裸的是N^2 利用线段树可以降到NlogN 具体方法是插入一 ...

  5. codeblocks 使用指南z

    1.界面风格更改 首先贴怎么普通设置出来,或者改配置文件 这是我的风格 类似于DEV-CPP里面的一个主题,看的很舒服 具体设置如下: Settings-Editor 1.代码当前行高亮 在Gener ...

  6. UVA 1617 Laptop

    题意: 有n条长度为1的线段,确定他们的起点,必须是整数,使得第i条线段在[ri,di]之间.最后输出空隙的最小值 分析: 原始数据排序,排序的规则是先按照右端点排序,右端点相同的情况下,再按照左端点 ...

  7. Java日志管理

    首页 资讯 精华 论坛 问答 博客 专栏 群组 更多 ▼ 您还未登录 ! 登录 注册 JavaCrazyer的ItEye(codewu.com)技术博客   博客 微博 相册 收藏 留言 关于我   ...

  8. JQ第一篇

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. Android系统环境变量配置

    ANDROID_HOME D:\Program Files\Android-sdk D:\AndroidSDK\android-sdk ANDROID_SDK_HOME %ANDROID_HOME% ...

  10. [Linked List]Sort List

    otal Accepted: 59473 Total Submissions: 253637 Difficulty: Medium Sort a linked list in O(n log n) t ...