Home Database Mysql Tutorial Oracle发送邮件存储过程

Oracle发送邮件存储过程

Jun 07, 2016 pm 02:57 PM
oracle introduce send storage process mail

哎,每次都介绍,有啥好介绍的呢;好吧, 版权完全是我的,转载要说明出处哦。 无 CREATE OR REPLACE PROCEDURE SEND_MAIL_one(as_recp in varchar2, --邮件接收者 as_subject in varchar2, --邮件标题 as_msg_body in varchar2) --邮件内容 IS ls_mailhost v

哎,每次都介绍,有啥好介绍的呢;好吧, 版权完全是我的,转载要说明出处哦。
CREATE OR REPLACE PROCEDURE SEND_MAIL_one(as_recp     in varchar2, --邮件接收者
                                          as_subject  in varchar2, --邮件标题
                                          as_msg_body in varchar2) --邮件内容
 IS
  ls_mailhost  varchar2(30) := '192.168.0.1'; -- 邮件服务地址
  lc_mail_conn utl_smtp.connection;
  ls_subject   varchar2(100);
  ls_msg_body  varchar2(20000);
  --邮件服务器上发件人的帐号和密码
  ls_username  varchar2(256) := 'fajian@xxx.com';
  ls_password varchar2(256) := '123456';
BEGIN
  lc_mail_conn := utl_smtp.open_connection(ls_mailhost, 25);--在特定地址特定端口获得链接
  utl_smtp.helo(lc_mail_conn, ls_mailhost);
  utl_smtp.command(lc_mail_conn, 'AUTH LOGIN');
  utl_smtp.command(lc_mail_conn,
                   demo_base64.encode(utl_raw.cast_to_raw(ls_username)));
  utl_smtp.command(lc_mail_conn,
                   demo_base64.encode(utl_raw.cast_to_raw(ls_password)));
  ls_subject  := 'Subject: [' || upper(sys_context('userenv', 'db_name')) ||
                 '] - ' || convert(as_subject, 'ZHS16GBK', 'AL32UTF8');
  ls_msg_body := convert(as_msg_body, 'ZHS16GBK', 'AL32UTF8');

  utl_smtp.mail(lc_mail_conn, '<' || '发件人sxgkwei' || '>'); 
  utl_smtp.rcpt(lc_mail_conn, '<' || as_recp || '>'); 
  utl_smtp.open_data(lc_mail_conn);

  ls_msg_body := 'From: ' || '发件人sxgkwei' || chr(13) || chr(10) ||
                 'To: ' || as_recp || chr(13) || chr(10) || ls_subject ||
                 chr(13) || chr(10) || chr(13) || chr(10) || ls_msg_body;

  utl_smtp.write_raw_data(lc_mail_conn, utl_raw.cast_to_raw(ls_msg_body));

  utl_smtp.close_data(lc_mail_conn);
  utl_smtp.quit(lc_mail_conn);
EXCEPTION
  WHEN UTL_SMTP.INVALID_OPERATION THEN
    dbms_output.put_line('invalid operation');
  WHEN UTL_SMTP.TRANSIENT_ERROR THEN
    dbms_output.put_line('transient error');
  WHEN UTL_SMTP.PERMANENT_ERROR THEN
    dbms_output.put_line('permanent error');
  
  WHEN OTHERS THEN
    dbms_output.put_line('others');
end SEND_MAIL_one;
Copy after login
CREATE OR REPLACE PROCEDURE SEND_MAIL(as_recp in varchar2, --邮件接收者,多接收者可用';'号分隔
                                      
                                      as_subject  in varchar2, --邮件标题
                                      as_msg_body in varchar2) --邮件内容
 IS
  type myArr is table of varchar2(500) index by binary_integer;
  i           number;
  l_idx       number;
  recp        varchar2(500);
  as_recp_arr myArr;
BEGIN
  recp  := as_recp;
  i     := 1;
  l_idx := instr(recp, ';');

  while l_idx > 0 loop
    as_recp_arr(i) := substr(recp, 1, l_idx - 1);
    recp := substr(recp, l_idx + 1);
    i := i + 1;
    l_idx := instr(recp, ';');
  end loop;

  if length(recp) > 1 then
    as_recp_arr(i) := recp;
  end if;

  for i in 1 .. as_recp_arr.count loop
    SEND_MAIL_one(as_recp_arr(i), as_subject, as_msg_body);
  end loop;
end send_mail;
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to view instance name of oracle How to view instance name of oracle Apr 11, 2025 pm 08:18 PM

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

How to uninstall Oracle installation failed How to uninstall Oracle installation failed Apr 11, 2025 pm 08:24 PM

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

How to delete all data from oracle How to delete all data from oracle Apr 11, 2025 pm 08:36 PM

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

How to set up users of oracle How to set up users of oracle Apr 11, 2025 pm 08:21 PM

To create a user in Oracle, follow these steps: Create a new user using the CREATE USER statement. Grant the necessary permissions using the GRANT statement. Optional: Use the RESOURCE statement to set the quota. Configure other options such as default roles and temporary tablespaces.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to check invalid numbers of oracle How to check invalid numbers of oracle Apr 11, 2025 pm 08:27 PM

Oracle Invalid numeric errors may be caused by data type mismatch, numeric overflow, data conversion errors, or data corruption. Troubleshooting steps include checking data types, detecting digital overflows, checking data conversions, checking data corruption, and exploring other possible solutions such as configuring the NLS_NUMERIC_CHARACTERS parameter and enabling data verification logging.

See all articles