zoukankan      html  css  js  c++  java
  • 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 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?

  • 相关阅读:
    Oracle 按一行里某个字段里的值分割成多行进行展示
    Property or method "openPageOffice" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by
    SpringBoot 项目启动 Failed to convert value of type 'java.lang.String' to required type 'cn.com.goldenwater.dcproj.dao.TacPageOfficePblmListDao';
    Maven 设置阿里镜像
    JS 日期格式化,留作参考
    JS 过滤数组里对象的某个属性
    原生JS实现简单富文本编辑器2
    Chrome控制台使用详解
    android权限(permission)大全
    不借助第三方网站四步实现手机网站转安卓APP
  • 原文地址:https://www.cnblogs.com/huak/p/3853417.html
Copyright © 2011-2022 走看看