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 [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(‘[email protected]‘, ‘[email protected]‘, ‘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?

时间: 2024-11-09 22:09:47

How to Send an Email Using UTL_SMTP with Authenticated Mail Server的相关文章

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 applies to any platform.***Checked for relevance on 07-Apr-2014*** GOAL The UTL_SMTP package is designed for sending electronic mails (emails) over Sim

Java发送Email—使用org.apache.commons.mail

上篇文章介绍了自己手动的实现发送普通Email.HTML类型的Email以及带附件的Email.其实apache的commons项目下有个email子项目,它对JavaMail API进行了封装,用起来特变方便.下面就简单介绍. 1.    首先配置需要的jar包 需要将mail.jar和commons-email.jar添加到我们的CLASSPATH中即可,如下图: 2.    发送普通邮件 /** * 用org.apache.commons.mail发送普通邮件 * * @author wa

aliyun install Discourse log

apt update apt install wget wget -qO- https://get.docker.com/ | sh vim /etc/default/docker DOCKER_OPTS="--registry-mirror=http://aad0405c.m.daocloud.io" service docker restart mkdir /var/discourse git clone https://github.com/discourse/discourse

Use powershell script against password hacking over OWA

In my previous company Exchange OWA isn't published to internet, so this blog described my first time encountering hacker trying to hack my new company's Active directory passwords. Based on it, I wrote a powershell script running on each CAS servers

roundup配置

原因:我需要一个简单的issue tracker why roundup: python,简单 找了半天的文档,找不到文档,只能自己慢慢试,试到现在,可以打开tracker页面,用户注册的时候可以发邮件到admin的邮箱 # Roundup issue tracker configuration file # Autogenerated at Wed Jul 3 18:34:31 2013 # WARNING! Following options need adjustments: # [mai

2-Application Layer

Please indicate the source: http://blog.csdn.net/gaoxiangnumber1 Welcome to my github: https://github.com/gaoxiangnumber1 2.1 Principles of Network Applications 2.1.1 Network Application Architectures Application's architecture is different from the

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. (文档 ID 604763.1) 转到底部 修改时间:2014-5-13类型:PROBLEM 为此文档评级 通过电子邮件发送此文档的链接 在新窗口中打开文档 In this Document   Symptoms   Cause   Solution   References APPLIES TO: PL/S

Send email alert from Performance Monitor using PowerShell script (检测windows服务器的cpu 硬盘 服务等性能,发email的方法) -摘自网络

I have created an alert in Performance Monitor (Windows Server 2008 R2) that should be triggered whenever \Processor(_Total)\% Processor Time is Above 10 (a small value just to guarantee that the condition for sending the alert is always met). You ca

[HTML5] Can I use HTML5 to send a client-side email?

摘要:[HTML5] Can I use HTML5 to send a client-side email? http://stackoverflow.com/questions/5467395/can-i-use-html5-to-send-a-client-side-email Question I want to send an email in HTML5. I don't want to force the user to open a mail client, I want to