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. 适配器模式(adapter)

    适配器模式的定义: 将一个类的接口转换成客户希望的另外一个接口,适配器模式使得原本由于接口不兼容而不能在一起的那些类可以一起工作. 主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式. ...

  2. x264源代码简单分析:编码器主干部分-2

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  3. [ExtJS5学习笔记]第三十一节 sencha extjs 5使用cmd生成的工程部署到tomcat服务器

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/42940883 本文作者:sushengmiyan ------------------ ...

  4. 【java集合框架源码剖析系列】java源码剖析之HashSet

    注:博主java集合框架源码剖析系列的源码全部基于JDK1.8.0版本.本博客将从源码角度带领大家学习关于HashSet的知识. 一HashSet的定义: public class HashSet&l ...

  5. Eclipse 主题

    Eclipse开发环境默认都是白底黑字的,看到同事的Xcode中设置的黑灰色背景挺好看的,就去网络上查了一下.发现Eclipse也可以设置主题. http://eclipsecolorthemes.o ...

  6. (八十六)使用系统自带的分享框架Social.framework

    使用Social.framework十分简单,能够便捷的分享到主流的社交框架. ①导入主头文件 #import <Social/Social.h> ②以新浪微博为例,首先判断服务是否可用, ...

  7. UNIX环境高级编程——线程和fork

    当线程调用fork时,就为子进程创建了整个进程地址空间的副本.子进程通过继承整个地址空间的副本,也从父进程那里继承了所有互斥量.读写锁和条件变量的状态.如果父进程包含多个线程,子进程在fork返回以后 ...

  8. Win7 Eclipse Hadoop2.4插件配置

    准备工作: 1.下载hadoop2x-eclipse-plugin-master.zip Github地址:https://github.com/winghc/hadoop2x-eclipse-plu ...

  9. Mybatis插入MySQL数据库中文乱码

    Mybatis插入MySQL数据库中文乱码 在dataSource.properties配置文件中设置useUnicode=true&characterEncoding=utf-8编码即可. ...

  10. 摆脱命令行,Ubuntu下配置Android开发环境

    作者:宋志辉 微博:weibo.com/askzhihui/ 安装所需工具 一.新立得 新立得(Synaptic)是Debian和Ubuntu Linux操作系统的包管理工具apt的图形化前端. 它结 ...