Sending Email from PL/SQL on Oracle 8.05...

Hi,
I need to send an email from PL/SQL, my database is on Windows
server and it's 8.05 (sorry we're late on upgrading:(...)
Thanks in advance
Cecmlia

Hello,
Here is sample code for sending mail using PL/SQL.
This PL/sql Procedure sends mails using SMTP server.
Author - Mr. Adinath R. Kamode
Date - 08/05/2001
procedure sendmail is
c utl_smtp.connection; -- Connectio type variable
v_from varchar2(200);
v_from1 varchar2(200);
v_to varchar2(200);
PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2)
AS
BEGIN
-- Generates header data required from mail
utl_smtp.write_data(c, name || ': ' || header ||
utl_tcp.CRLF);
END;
begin
c := utl_smtp.open_connection('smtp_server.pc150'); --
Specify your SMTP -- server
address here
utl_smtp.helo(c, 'pc150');
-- Define sender and receiver
utl_smtp.mail(c, '[email protected]');
utl_smtp.rcpt(c, '[email protected]');
utl_smtp.open_data(c);
send_header
('From','Sender<[email protected]>');
send_header
('To', 'Recipient<[email protected]>');
send_header('Subject', 'Hello');
utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!');
utl_smtp.close_data(c);
utl_smtp.quit(c);
end;
Adi

Similar Messages

  • Sending email from PL/SQL in oracle

    This is the sample code
    DECLARE
    l_mailhost VARCHAR2(64) := 'mail.mycompany.com';
    l_from VARCHAR2(64) := '[email protected]';
    l_to VARCHAR2(64) := '[email protected]';
    l_mail_conn UTL_SMTP.connection;
    BEGIN
    l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
    UTL_SMTP.helo(l_mail_conn, l_mailhost);
    UTL_SMTP.mail(l_mail_conn, l_from);
    UTL_SMTP.rcpt(l_mail_conn, l_to);
    UTL_SMTP.data(l_mail_conn, 'Single string message.' || Chr(13));
    UTL_SMTP.quit(l_mail_conn);
    END;
    In that how to find mail host.

    1) Install a mail server on your local machine
    2) or user any mail server free or paid if you are connected to internet.
    3) Get the hostname of the mail server from you network admin or mail server admins
    SS

  • Send email from PL/SQL trigger on Solaris

    I searched all of the Oracle site looking for this capability, and found many messages several months old essentially saying there is no easy way to do this. I thought I remembered seeing an example of this in the online documentation, but of course I can't find that now. Is there any simple way of sending email from within an insert trigger written with PL/SQL?

    Try the pl/sql code below.
    create or replace PROCEDURE send_test_message
    IS
    mailhost VARCHAR2(64) := '191.168.251.207'; -- ip address of the mail server.
    sender VARCHAR2(64) := '[email protected]';
    recipient VARCHAR2(64) := '[email protected]';
    mail_conn utl_smtp.connection;
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipient);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn, 'Your leave is Cancelled due to xyz...reason ' || chr(13));
    utl_smtp.write_data(mail_conn, 'This is line 2.' || chr(13));
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS THEN
    -- Insert error-handling code here
    NULL;
    END;

  • How to send emails from HANA SQL Console

    Hi,
    Please guide how  to send mail from HANA Studio SQL Console.
    Is there any standard procedure in Hana Studio to send Mail( e.g. in MS SQL  "sp_send_dbmail" Procedure)

    Hi Preethi,
    Please go through the attached link:
    How to send emails from HANA
    Regards,
    Krishna

  • How we send email from pl/sql

    i want 2 send mail from pl/sql??
    plz tell me bout d coding related to this.
    i really appreciated ur help.

    Try the pl/sql code below.
    create or replace PROCEDURE send_test_message
    IS
    mailhost VARCHAR2(64) := '191.168.251.207'; -- ip address of the mail server.
    sender VARCHAR2(64) := '[email protected]';
    recipient VARCHAR2(64) := '[email protected]';
    mail_conn utl_smtp.connection;
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipient);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn, 'Your leave is Cancelled due to xyz...reason ' || chr(13));
    utl_smtp.write_data(mail_conn, 'This is line 2.' || chr(13));
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS THEN
    -- Insert error-handling code here
    NULL;
    END;

  • Send a email from PL SQL

    hii All,
    I need a help! :(,
    i want to create a pl sql block to send an email with the result of a select the table DBA_TABLES and attached a txt file and / or pdf
    pls anyone can help me ?
    i use ORACLE 11g
    my parameter of smtp_out_server is 'smtp.gmail.com', well i dont know that is correct, if no, please put the correct.
    thank you alot.
    Pd: sorry for my bad english.

    Hi
    You can user utl_mail package for send emails from pl/sql. Try like this....!!!
    rerequisites:
       I need to execute these two scripts as sysdba;
       @$ORACLE_HOME/rdbms/admin/utlmail.sql;
       @$ORACLE_HOME/rdbms/admin/prvtmail.plb;
       Then you have to configure smtp server information in init.ora file . or spfile.
       smtp_out_server = 'smtp.gmail.com'
       Then execute this commond as sysdba;
       alter system set smtp_out_server = 'smtp.gmail.com'  scope=both;
         exec utl_mail.send(sender => '[email protected]',
                           recipients => '[email protected]','[email protected]',
                           subject => 'Testing Mail',
                           message => 'Hi..This is a test mail');
    grant execute permission on UTL_MAIL package.
    eg: grant execute on utl_mail to <your schema>;KPR

  • Send email from oracle

    Dear member & developers
    I want to send e mail from oracle application. If anybody knows, how to do this. please write or send a sample application or forms or database sql. I don't restricted to any application version like 10g or 11g same as database...
    I seriously need it.
    Thanks in Advanced.

    As Francois indicated - there are multiple examples around the internet and in the forums. Any email solution you choose is going to require that you have access to a valid email server (SMTP, POP3, etc). Also, the solution is dependent on "Where" you want to send the email from. I prefer a database solution because this makes it available to your entire database application, but you can use a Java email method (using Forms PJC or Java Bean) or you can OLE link to Microsoft Outlook.
    Take a look at Send Email from the Database. I wrote this package based on the DEMO_MAIL package provided by Oracle (via OTN) and stream line things a bit. There is an example of how to use the package in the article.
    Take a look at Send email with HTML body and local file attachements article on Franscois's web site for an example of sending email from an Oracle Form using Java.
    If you need to use Outlook - search the forum. I don't consider this to be a reasonable method so I don't use it or recommend it. I'm sure it works fine for others, I just think being dependent on a application installed on the client is not a solid solution. That's just my opinion. ;-)
    I search through out the net. Didn't get any tutorial video or any working materiel. I disagree with this statement - I did a quick Google search and found many examples (no videos) and demo's.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Sending Email from PLSql Oracle 8.0.6

    Has anyone got any ideas or achieved this: Sending Email from PLSql for Oracle version 8.0.6 using the limited technology support in this version, i.e. UTL_SMTP & UTL_TCP are not supported.
    Any help will be greatly appreciated.

    Sending Email from PLSql for Oracle version 8.0.6 using the limited technology
    support in this version, i.e. UTL_SMTP & UTL_TCP are not supported.That's because they use Java and Java doesn't work with versions older than 8i. Does 8.0 support external procedures (I went straight from 7.3.4 to 8.1.6)? If so you might be able to cobble together some C to interface with smtp on the OS. Otherwise I think you're looking at writing some client-side application to do this.
    Cheers, APC

  • ACL error when sending email from Oracle 11g

    Hi,
    It returned something like "error...ACL security" when I tried to send email from Oracle 11g. Is there any security thing that I need to release in Oracle 11g? I used to send emails from Oracle 10g and didn't find any problem.
    Thanks.
    Andy

    In Database 11g Oracle introduced Network Access Control Lists (ACLs) to protect the database from users using the many internet-capable packages such as UTL_INADDR, UTL_HTTP, UTL_TCP, etc.
    Read all about it in the docs and look at the code demos here:
    http://www.morganslibrary.org/library.html
    under DBMS_NETWORK_ACL_...

  • How to sending email from Oracle 6i(Forms)

    How can I send email from Oracle Forms(6i).
    I need to send email to a distribution list(multiple email addresses).

    send email of multiple email address
    [email protected],[email protected],[email protected]
    create or replace function mailout
    (sender in varchar2,
    recipient in varchar2,
    ccrecipient in varchar2,
    subject in varchar2,
    message in varchar2) return number
    is
    crlf varchar2(2) := chr(13)||chr(10);
    connection utl_smtp.connection;
    mailhost varchar2(50) := 'Add email server Ip Address here';
    header varchar2(4000);
    v_num number :=1;
    str number:=0;
    email varchar2(50);
    begin
    connection := utl_smtp.open_connection(mailhost,25);
    header := 'Date: '||to_char(sysdate,'dd mon yy hh24:mi:ss')||crlf||
    'From: '||sender||' '||crlf||
    'Subject: '||subject||crlf||
    'To: '||recipient||crlf||
    'Cc: '||ccrecipient||crlf||message;
    utl_smtp.helo(connection,mailhost);
    utl_smtp.mail(connection,sender);
    utl_smtp.rcpt(connection,recipient);
    while (instr(ccrecipient,',',1,v_num)>0) loop
    email:=substr(ccrecipient,str+1,instr(ccrecipient,',',1,v_num)-str-1);
    dbms_output.put_line(email);
    utl_smtp.rcpt(connection,email);
    str:=instr(ccrecipient,',',1,v_num);
    v_num:=v_num+1;
    end loop;
    utl_smtp.open_data(connection);
    -- utl_smtp.write_data(connection,header);
    utl_smtp.write_data(connection,'MIME-Version:1.0'||crlf||'Content-type:text/html'||crlf||header);
    utl_smtp.close_data(connection);
    utl_smtp.quit(connection);
    return 0;
    exception
    when utl_smtp.invalid_operation then
    dbms_output.put_line('Invalid Operation in SMTP transaction');
    return 1;
    when utl_smtp.transient_error then
    dbms_output.put_line('Temporary problem with sending email ');
    return 2;
    when utl_smtp.permanent_error then
    dbms_output.put_line('Permanent problem with sending email ');
    return 3;
    end;

  • How to send emails from of pdf's generated by oracle reports

    I have several pdf documents , I want to email those pdf's . Please let me know how to send emails from oracle reports .
    Thanks,
    Previn

    I have integrated Oracle Reports with Oracle Portal and used the scheduling feature via portlets. We have reports that run every monday morning for management. For more info go to:
    http://otn.oracle.com/products/reports/htdocs/getstart/demonstrations/index.html
    OR
    I think if you set destype=mail, desformat=PDF, and desname=[email protected] that should also do the trick.
    Just be sure that you have put your mail server's IP address in the rep_<machine_name>.conf file located in your <oracle_home>/reports/conf directory. If this is not set up, the mail feature won't work.
    Martin

  • How to sending email from Oracle Forms

    How to sending email from Oracle 6i(Forms)
    I need to send email to a distribution list(multiple email addresses).

    send email of multiple email address
    [email protected],[email protected],[email protected]
    create or replace function mailout
    (sender in varchar2,
    recipient in varchar2,
    ccrecipient in varchar2,
    subject in varchar2,
    message in varchar2) return number
    is
    crlf varchar2(2) := chr(13)||chr(10);
    connection utl_smtp.connection;
    mailhost varchar2(50) := 'Add email server Ip Address here';
    header varchar2(4000);
    v_num number :=1;
    str number:=0;
    email varchar2(50);
    begin
    connection := utl_smtp.open_connection(mailhost,25);
    header := 'Date: '||to_char(sysdate,'dd mon yy hh24:mi:ss')||crlf||
    'From: '||sender||' '||crlf||
    'Subject: '||subject||crlf||
    'To: '||recipient||crlf||
    'Cc: '||ccrecipient||crlf||message;
    utl_smtp.helo(connection,mailhost);
    utl_smtp.mail(connection,sender);
    utl_smtp.rcpt(connection,recipient);
    while (instr(ccrecipient,',',1,v_num)>0) loop
    email:=substr(ccrecipient,str+1,instr(ccrecipient,',',1,v_num)-str-1);
    dbms_output.put_line(email);
    utl_smtp.rcpt(connection,email);
    str:=instr(ccrecipient,',',1,v_num);
    v_num:=v_num+1;
    end loop;
    utl_smtp.open_data(connection);
    -- utl_smtp.write_data(connection,header);
    utl_smtp.write_data(connection,'MIME-Version:1.0'||crlf||'Content-type:text/html'||crlf||header);
    utl_smtp.close_data(connection);
    utl_smtp.quit(connection);
    return 0;
    exception
    when utl_smtp.invalid_operation then
    dbms_output.put_line('Invalid Operation in SMTP transaction');
    return 1;
    when utl_smtp.transient_error then
    dbms_output.put_line('Temporary problem with sending email ');
    return 2;
    when utl_smtp.permanent_error then
    dbms_output.put_line('Permanent problem with sending email ');
    return 3;
    end;

  • Monitor sending emails from Oracle level

    Want to monitor sending of emails from scot at the oracle level.  I know tables SOST is used, not sure what fields could be monitored to determine if emails are just sitting in queue.

    Hi,
    Check out http://www.oracle.com/pls/xe102/search?remark=advanced_search&word=email&format=ranked&format=drilldown&book=&preference=
    (and bookmark http://www.oracle.com/pls/xe102/homepage ;) )

  • Sending email from DB to gmail

    All,
    I am on Oracle Database 11g Express Edition Release 11.2.0.2.0
    Could anyone please help me on this. I am trying to get a sample code to send an email from DB to gmail/yahoo ( any mail client).
    I have followed the instructions as said in the Send mail from PL/SQL - Oracle FAQ. But not able to send an email to gmail.
    SQL> conn sys as sysdba
    Enter password:
    Connected.
    SQL> @ D:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\prvtmail.plb
    Package created.
    Package body created.
    Grant succeeded.
    Package body created.
    No errors.
    SQL> @ D:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\utlmail.sql
    Package created.
    Synonym created.
    SQL> select name, value from v$parameter where name like '%smtp%';
    NAME
    VALUE
    smtp_out_server
    SQL> alter session set smtp_out_server='127.0.0.1';
    Session altered.
    SQL> select name, value from v$parameter where name like '%smtp%';
    NAME
    VALUE
    smtp_out_server
    127.0.0.1
    SQL> BEGIN
      2    --EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''127.0.0.1''';
      3    UTL_MAIL.send(sender => '[email protected]',
      4              recipients => '[email protected]',
      5                 subject => 'Test Mail',
      6                 message => 'Hello World',
      7               mime_type => 'text; charset=us-ascii');
      8  END;
      9  /
    BEGIN
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_MAIL", line 654
    ORA-06512: at "SYS.UTL_MAIL", line 671
    ORA-06512: at line 3
    SQL>
    Also i have tried another way as the below, but the same no result. Could anyone please help me out to send an email from DB to gmail / yahoomail. And also please tell me where can i find the settings for SMTP of gmail / ymail.
    SQL> DECLARE
      2    v_c UTL_SMTP.connection;
      3    v_mailserver VARCHAR2(40);
      4    v_from       VARCHAR2 (40);
      5    v_to         VARCHAR2 (40);
      6    v_cc         VARCHAR2 (40);
      7    v_subject    VARCHAR2 (40);
      8    v_resp UTL_SMTP.reply;
      9  BEGIN
    10    v_mailserver:='smtp.gmail.com';
    11    v_from      :='[email protected]';
    12    v_to        :='[email protected]';
    13    v_cc        :='[email protected]';
    14    v_subject   :='TEST MAIL';
    15    v_resp      :=UTL_SMTP.open_connection (v_mailserver, c=>v_c);
    16    v_resp      :=UTL_SMTP.helo (v_c, 'helo_text');
    17    v_resp      :=UTL_SMTP.mail (v_c, v_to);
    18    v_resp      :=UTL_SMTP.rcpt(v_c, v_from);
    19    v_resp      :=UTL_SMTP.open_data(v_c);
    20    UTL_SMTP.write_data(v_c, 'From: ' || v_from || UTL_TCP.crlf);
    21    UTL_SMTP.write_data (v_c,'To: ' || v_to || UTL_TCP.crlf);
    22    UTL_SMTP.write_data (v_c,'Cc: ' || v_cc || UTL_TCP.crlf);
    23    UTL_SMTP.write_data (v_c,'Subject: ' || v_subject || UTL_TCP.crlf);
    24    UTL_SMTP.write_data (v_c, 'Test Body');
    25    v_resp:=UTL_SMTP.close_data(v_c);
    26    UTL_SMTP.quit (v_c);
    27  END;
    28  /
    DECLARE
    ERROR at line 1:
    ORA-29279: SMTP permanent error: 502 5.5.1 Unrecognized command.
    jh13sm1540092bkb.13 - gsmtp
    ORA-06512: at "SYS.UTL_SMTP", line 54
    ORA-06512: at "SYS.UTL_SMTP", line 140
    ORA-06512: at "SYS.UTL_SMTP", line 699
    ORA-06512: at line 26
    Also, is it possible to send the email from db to an email id which is on microsoft exchange server. if so, what are setting needed.
    Thank you all.

    Hello,
    did you try to search this forum? You are not the first to ask this question
    SQL and PL/SQL ?query=gmail
    Regards
    Marcus

  • Sending email from database version 8.0.5

    Hi!
    We are current using Oracle Database 8.0.5. How can we send email using PL/SQL?
    utl_smtp is not yet available i think for this database version? what is the alternative? How do we use/install this alternative.
    Please help. Thanks.
    Erick

    Here is our Oracle version from SQL*Plus:
    SQL> select * from v$version;
    BANNER
    Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
    PL/SQL Release 8.1.5.0.0 - Production
    CORE Version 8.1.5.0.0 - Production
    TNS for 32-bit Windows: Version 8.1.5.0.0 - Production
    NLSRTL Version 3.4.0.0.0 - Production
    I got this error from my procedure:
    PLS-00201: identifier 'UTL_SMTP.CONNECTION' must be declared
    Is this version not enough to run UTL_SMTP?

Maybe you are looking for