首页 > 解决方案 > 我想使用 oracle apex 将我的电子邮件日志保存到我的个人表中

问题描述

我正在使用 apex_mail.send() 顶点邮件程序,现在我的目标是维护它的日志到另一个表。每当从 apex_mail.send() 程序发送电子邮件时,它都会将我的表中的每个条目都保存为日志。

DECLARE
    l_body      CLOB;
    l_body_html CLOB;
BEGIN
    l_body := 'To view the content of this message, please use an HTML enabled mail client.'||utl_tcp.crlf;

    l_body_html := '<html>
        <head>
            <style type="text/css">
                body{font-family: Arial, Helvetica, sans-serif;
                    font-size:10pt;
                    margin:30px;
                    background-color:#ffffff;}

                span.sig{font-style:italic;
                    font-weight:bold;
                    color:#811919;}
             </style>
         </head>
         <body>'||utl_tcp.crlf;
    l_body_html := l_body_html ||'<p>Thank you for your interest in the <strong>APEX_MAIL</strong> package.</p>'||utl_tcp.crlf;
    l_body_html := l_body_html ||'  Sincerely,<br />'||utl_tcp.crlf;
    l_body_html := l_body_html ||'  <span class="sig">The APEX Dev Team</span><br />'||utl_tcp.crlf;
    apex_mail.send(
    p_to   => 'some_user@somewhere.com',   -- change to your email address
    p_from => 'some_sender@somewhere.com', -- change to a real senders email address
    p_body      => l_body,
    p_body_html => l_body_html,
    p_subj      => 'APEX_MAIL Package - HTML formatted message');
END;

标签: sqloracle-apexoracle-apex-5oracle-apex-18.2oracle-apex-19.1

解决方案


为确保您记录对 的每次调用apex_mail.send,请创建一个记录调用的包装程序(或包),并且仅在发送电子邮件时使用您的包装程序。

例如:

create or replace package my_mail as
  procedure send( ... );
  ...
end;
/

create or replace package body my_mail as
  procedure send( ... ) as
  begin
    insert into log_table (column list) values (parameter value list);
    ...
    <additional custom code>
    ...
    apex_mail.send( ... );
  end;
  ...
end;
/

作为使用您自己的包装器的一个附带好处,您可以添加额外的功能,例如在开发或 UAT 环境中自动将收件人地址重写为测试地址,这样您就不会意外地向真实用户发送测试数据垃圾邮件。


推荐阅读