Send a mail using Oracle's Utility UTL_SMTP

Below is the sample code to send a mail using Oracle's Utility UTL_SMTP.....
  create or replace procedure xxsammail as
    L_recipient VARCHAR2 (80) := 'vvydhyal@cisco.com';
    L_from VARCHAR2 (80) := 'vvydhyal@cisco.com';
    L_mail_host VARCHAR2 (30) := 'mailman.cisco.com';
    L_subject VARCHAR2 (80) := 'This is a Test Mail';
    L_mail_conn UTL_SMTP.connection;
begin
     L_mail_conn := UTL_SMTP.open_connection (L_mail_host, 25);
     UTL_SMTP.helo (L_mail_conn, L_mail_host);
     UTL_SMTP.mail (L_mail_conn, L_from);
     UTL_SMTP.rcpt (L_mail_conn, L_recipient);
     --UTL_SMTP.DATA (L_mail_conn,'Hellllooooo');
     utl_smtp.data(L_mail_conn,'From: Oracle Database'||utl_tcp.crlf ||
                                          'To: '||L_recipient||utl_tcp.crlf||
                                          'Subject: '||L_subject||utl_tcp.crlf||L_message);
      UTL_SMTP.quit (L_mail_conn);
exception
    when others then
         dbms_output.put_line('Error : ' ||sqlerrm);
end;

--------------------================================
begin
    xxsammail;
exception
    when others then
        dbms_output.put_line('Error : ' ||sqlerrm);
end;

No comments:

Post a Comment