如何在 PL/SQL (Oracle) 中发送电子邮件? [英] How Can I Send Emails in PL/SQL (Oracle)?
问题描述
我有一个程序可以计算 SMS_OUTBOX 表中的行数,并在其行数超过 1000 时发送电子邮件.我的程序如下:
I have a procedure which count the number of rows in SMS_OUTBOX table and send emails if its row cont is over 1000. My procedure is given below:
CREATE OR REPLACE PROCEDURE SEND_EMAIL_ABOUT_PENDING_SMS IS
CHECK_SMS_COUNT NUMBER := 1000;
CURRENT_SMS_COUNT NUMBER;
BEGIN
SELECT COUNT(1) INTO CURRENT_SMS_COUNT FROM SMS_SCHEMA.SMS_OUTBOX;
IF CURRENT_SMS_COUNT >= CHECK_SMS_COUNT THEN
UTL_MAIL.SEND(
sender=>'<SENDER_EMAIL>',
recipients=>'<RECIPIENT_EMAIL>',
subject=>'Pending SMS',
Message=>'Pending SMS count exceeded.'
);
END IF;
END SEND_EMAIL_ABOUT_PENDING_SMS;
/
当我编译上面的代码时,我收到了这个错误.
When I compile the above I got this error.
然后我尝试在没有程序的情况下执行这行代码:
Then I tried this line of code to execute without the procedure:
EXEC UTL_MAIL.SEND(
sender=>'<SENDER_EMAIL>',
recipients=>'<RECIPIENT_EMAIL>',
subject=>'Pending SMS',
Message=>'Pending SMS count exceeded.'
);
然后我得到这个错误:
PLS-00302:必须声明组件SEND"
我对 Oracle(和 PL/SQL)非常陌生.任何人都可以帮助我在 Oracle 中发送电子邮件以及需要哪些配置?
I am very new to Oracle (and PL/SQL). Can anyone please help me on sending emails in Oracle and what are the configurations needed?
推荐答案
请检查UTL_MAIL是否安装正确.
Please check whether UTL_MAIL has been installed properly.
点击链接UTL_MAIL 需要的信息和配置
Follow the link UTL_MAIL for information and configuration required
Setup
The package is loaded by running the following scripts.
CONN sys/password AS SYSDBA
@$ORACLE_HOME/rdbms/admin/utlmail.sql
@$ORACLE_HOME/rdbms/admin/prvtmail.plb
In addition the SMTP_OUT_SERVER parameter must be set to identify the SMTP server.
CONN sys/password AS SYSDBA
ALTER SYSTEM SET smtp_out_server='smtp.domain.com' SCOPE=SPFILE;
-- Instance restart only necessary in 10gR1.
SHUTDOWN IMMEDIATE
STARTUP
这篇关于如何在 PL/SQL (Oracle) 中发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!