Reg : Sending mails from PL/SQL

Hello,
I've written the following code for sending mails from PL/SQL.
But the application gets hanged during compilation itself. Could
any of u please tell me why it's happening and what is wrong in
this and suggest me how to do it ??????
CREATE OR REPLACE PROCEDURE SEND_MAIL
IS
msg_from varchar2(50) := '[email protected]';
msg_to varchar2(50) := '[email protected]';
msg_subject varchar2(100) := 'E-Mail message from your database';
msg_text varchar2(1000) := '';
c utl_tcp.connection;
rc integer;
BEGIN
c := utl_tcp.open_connection('172.16.48.1', 80); -- open the
SMTP
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'HELO localhost');
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from);
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to);
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'DATA'); -- Start message body
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'Subject: '||msg_subject);
rc := utl_tcp.write_line(c, '');
rc := utl_tcp.write_line(c, msg_text);
rc := utl_tcp.write_line(c, '.'); -- End of message body
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
rc := utl_tcp.write_line(c, 'QUIT');
dbms_output.put_line(utl_tcp.get_line(c, TRUE));
utl_tcp.close_connection(c); -- Close the connection
EXCEPTION
when others then
raise_application_error(-20000,'Unable to send e-mail message
from pl/sql');
END;
Awaiting for ur reply,
Thanks in Advance...
Srinivas

FUNCTION Send_Mail ( sender IN VARCHAR2
     , recipient IN VARCHAR2
     , subject IN VARCHAR2
     , message IN VARCHAR2)
     RETURN BOOLEAN IS
     lv_mailhost VARCHAR2(30) := 'mailserver';
     l_mail_conn utl_smtp.connection;
     lv_crlf VARCHAR2(2):= CHR( 13 ) || CHR( 10 );
BEGIN
     l_mail_conn := utl_smtp.open_connection ( lv_mailhost
          , 25);
     utl_smtp.helo ( l_mail_conn
                    , lv_mailhost);
     utl_smtp.mail ( l_mail_conn
                    , sender);
     utl_smtp.rcpt ( l_mail_conn
                    , recipient);
     utl_smtp.open_data (l_mail_conn);
     utl_smtp.write_data ( l_mail_conn
                              , 'From: '
                              || sender
                              || lv_crlf);
     utl_smtp.write_data ( l_mail_conn
                              , 'To: '
                              || recipient
                              || lv_crlf);
     utl_smtp.write_raw_data ( l_mail_conn
utl_raw.cast_to_raw ( 'Subject:'
                    || subject
                    || lv_crlf));
     utl_smtp.write_raw_data ( l_mail_conn
utl_raw.cast_to_raw ( lv_crlf
                    || message));
utl_smtp.close_data(l_mail_conn);
     utl_smtp.quit(l_mail_conn);
     RETURN TRUE;
EXCEPTION
     WHEN OTHERS
     THEN
          RETURN FALSE;
END;

Similar Messages

  • Sending Mail from PL/SQL.

    Hi folks,
    I'm trying to send mail from PL/SQL (Database) with the help of UTL_SMTP.
    The pre-requisites for doing this are
    1) TCP/IP network.
    2) SMTP installation and accesibilty
    3) Oracle JServer installation.
    How do I check whether my database is having these three pre-requisites.
    Please bail me out from this problem.
    Your favour will be deeply appreciated.
    Cheers, PCZ.

    Hi,
    There nothing such prerequites, just u contact ur net admin team to relase your
    SMTP port in association with your empid id. and chk the port no 25 is also relased.
    And creating the procedure for sending mails. Refer the following link.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1739411218448
    Cheers , Hope this will do
    Nirmal Kumar

  • Send mail from PL/SQL with an attachment

    Hi,
    Can any body help me on how to send a mail from PL/SQL with an attachment which is located on a unix system path.
    This is an urgent requirement in my current project. Any quick reply would be greatly appreciated.
    Thanks
    Kumar.

    Quick reply (too bad you didn't mention your DB-version):
    Check the docs @ http://tahiti.oracle.com regarding packages UTL_SMTP and UTL_MAIL
    Check http://asktom.oracle.com/pls/asktom/asktom.search?p_string=%22mail+attachment%22
    Check http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
    Check http://www.oracle-base.com/articles/10g/PlsqlEnhancements10g.php#UTL_MAIL

  • Reg:Send mails from SAP

    Hi,
      Can anyone please help me out how to rectify this probleum.My issue is i am using  F.M "SO_DOCUMENT_REPOSITORY_MANAGER" for creating attachment and also for sending mails .But i want to send some text to body with signature along with the mail .How can it be done by using the above F.M.

    you use this FM
    objpack-doc_type   = 'TXT'.
    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        exporting
          document_data              = doc_chng
          put_in_outbox              = 'X'
          commit_work                = 'X'
        tables
          packing_list               = objpack
          object_header              = objhead
          contents_bin               = objbin
          contents_txt               = objtxt
          receivers                  = reclist
        exceptions
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          others                     = 99.

  • 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;

  • Sending E-Mail from PL/SQL

    I have used Oracle 9i (9.2.0.1) on windows Xp machine. I want to send e-mail
    from PL/SQL procedure.
    I execuete the procedure as follows friom SQL prompt in SCOTT user..
    execute prc_send_mail('[email protected]','[email protected]','Test message');
    before that I create the procedure in scott user and it is created successfully in scott user..
    Procedue is as follows...
    CREATE OR REPLACE PROCEDURE prc_send_mail (p_sender IN VARCHAR2,
    p_recipient IN VARCHAR2,
    p_message IN VARCHAR2)
    as
    l_mailhost VARCHAR2(255) := 'mail.yahoo.com';
    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, p_sender);
    utl_smtp.rcpt(l_mail_conn, p_recipient);
    utl_smtp.open_data(l_mail_conn );
    utl_smtp.write_data(l_mail_conn, p_message);
    utl_smtp.close_data(l_mail_conn );
    utl_smtp.quit(l_mail_conn);
    end;
    unfortunately i have receiveed some error which I mentioned below...
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_SMTP", line 17
    ORA-06512: at "SYS.UTL_SMTP", line 96
    ORA-06512: at "SYS.UTL_SMTP", line 138
    ORA-06512: at "SCOTT.PRC_SEND_MAIL", line 9
    ORA-06512: at line 1.
    Please anyone giove me the solution..

    > ORA-29278: SMTP transient error: 421 Service not available
    Not an Oracle error. This is the SMTP server telling you to go and get stuffed. It does not want to talk to you.
    See http://www.faqs.org/rfcs/rfc821.html.
    The RFC says that this type of response code can be for example when the SMTP server is about to shutdown - thus informing the client that it cannot be serviced.
    But seeing that you're trying to hijack mail.yahoo.com as your SMTP server.. I'm not surprise that the server is giving you the bird.

  • Cannot send mail from any mail account

    I have a Mac Mini, late 2014 model, running OS X Yosemite version 10.10.2.   I have constant difficulty sending mail from any of my mail accounts; these are iCloud, Googlemail, Yahoo and a personal one which uses 123-reg.co.uk.  I am currently located in Greece, but have been having trouble for ages, even in the UK.  I can receive mail, but I don't seem able to send it.  Error message is usually simply cannot send mail using this server, select a different server.  However, when connection doctor is run, all servers appear to be connected and I am logged in.  Any ideas please?

    rosiehwilson wrote:
    Hi, not sure why that is relevant, but we arrived at the end of January this year.  Here is a screen shot of a recurring problem, although in this case Gmail is not connected to the internet, which it usually is.  Hope this helps.
    Your outgoing Gmail servers not working, everything else seems OK.
    So, what is not working for you (other than Gmail Sending)

  • Sending mail from using utl_smtp error......

    Hi
    When i try to send mail like as follows
    DECLARE
    v_connection UTL_SMTP.CONNECTION;
    BEGIN
    v_connection := UTL_SMTP.OPEN_CONNECTION('xxx.xxx.xxx.xxx',25);
    UTL_SMTP.HELO(v_connection,'xxx.xxx.xxx.xxx');
    UTL_SMTP.MAIL(v_connection,'[email protected]');
    UTL_SMTP.RCPT(v_connection,'[email protected]');
    UTL_SMTP.DATA(v_connection,'Sent From PL/SQL');
    UTL_SMTP.QUIT(v_connection);
    END;
    I get the following error..
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_SMTP", line 17
    ORA-06512: at "SYS.UTL_SMTP", line 96
    ORA-06512: at "SYS.UTL_SMTP", line 138
    ORA-06512: at line 4
    if i send mail from outlook it goes...the configuration is like this
    in mail properties general tab
    email address : [email protected]
    and i have to tick mark the "include this account when receiving mail or synchro" option
    in servers tab
    POP3 : xxx.xxx.xxx.xxx
    smtp : xxx.xxx.xxx.xxx
    and i have to tick the "My server requires authentication" option
    and have to give the setting for that also
    ie. log on using account : [email protected]
         password: xxxxxx
    How to Correct it ?
    Kris

    i am on the same platform and in same account..... and PL/SQL UTL_SMTP gets a connection plus SMTP error, while telnet cannot even get a connection. A very weird one. Not sure what the problem can be.
    Worse case, forget telnet and do all your troubleshooting using UTL_SMTP.. with liberal usage of DBMS_OUTPUT. :-)
    regd. the connection from my xp client it is
    connecting to the telnet server on server, but when i
    tri to connect to the ISP's smtp address it throws
    the errorNot that strange. You're likely going through a proxy of sorts of to reach the ISP mail server. Besides, to send mail you should be able to use your company's SMTP server as it should route Internet e-mail out to the net automatically.
    In fact, many SMTP servers will not allow you to relay via them. E.g. if you connect from domain 1 to SMTP server on domain 2, and you submit an e-mail to be delivered to domain 3, the domain 2 server will tell you to take a hike. It will only accept mail that is destined for its own domain or originating from its own domain.
    Reason for this is spam. Open relays are one of the prime reasons for having billions of spam mails being transmitted.
    The correct method will be for you on domain 1 to connect to domain 1's SMTP server and submit an e-mail to be delivered to domain 3. That will be accepted and delivered. Using domain 2 as an intermediate agent to act as a relay, is/should not be accepted by all SMTP servers. (your SMTP server should get blacklisted/blackholed if it has an open relay)

  • Problem in sending mail from database with attachment

    Hi All,
    I amd using forms10g,oracle10g
    I am facing a error while running a procedure to send mail from db
    procedure is:
    declare
    ErrorMessage VARCHAR2(4000);
    ErrorStatus NUMBER;
    -- enable SQL*PLUS output;
    --SET SERVEROUTPUT ON
    -- redirect java output into SQL*PLUS buffer;
    --exec dbms_java.set_output(5000);
    BEGIN
    ErrorStatus := SendMailJPkg.SendMail(
    SMTPServerName => '192.168.4.2',
    Sender => '[email protected]',
    Recipient => '[email protected]',
    CcRecipient => '',
    BccRecipient => '',
    Subject => 'hth106: Test JavaMail',
    Body => 'This is the body: Hello, this is a test that spans 2 lines',
    AuthReqdYNNum => 1,
    UserID => 'jagan',
    Password => 'songbirds',
    ErrorMessage => ErrorMessage,
    Attachments => SendMailJPkg.ATTACHMENTS_LIST('C:\oramail\MHTHSO_GEN45.html')
    END;
    while running this procedure i am receiving following error
    "ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.IncompatibleClassChangeError"
    but the same procedure sending mail from all other user in the same database
    I am very myuch confused.i have given the all rights
    below mentioned rights are given .it is working in all other user on the same db except this user "hth106". And all the othere things are compared between working user and this hth106 user every things are same.But i am receiving error when i sending mail with attachment if the mail is sending without attachement it is working fine
    below rights are given to this user
    1.exec dbms_java.grant_permission('HTH106','java.util.PropertyPermission','*','read');
    2.exec dbms_java.grant_permission('HTH106','java.util.PropertyPermission','*','write');
    3.exec dbms_java.grant_permission('HTH106','java.net.SocketPermission','*','connect');
    4.exec dbms_java.grant_permission('HTH106','java.net.SocketPermission','*','resolve');
    5.exec dbms_java.grant_permission('HTH106','java.io.FilePermission','C:\oramail\*','read');
    exec dbms_java.grant_permission('HTH106','java.io.FilePermission','C:\oramail\*','write');
    6.call dbms_java.grant_permission('HTH106','java.net.SocketPermission','HTHDS01','resolve');
    7.call dbms_java.grant_permission('HTH106','java.util.PropertyPermission','*','read,write');
    7.call dbms_java.grant_permission('HTH106', 'java.io.FilePermission','C:\oramail\*','read');
    please advise me to proceed further
    Thanks in advance
    Thanks ,
    Antony

    With respects to the following:
    The bit you'll have most diffulty with is the attachment, because you can't be sure that
    the directory path specified is one that the database can read from. You can probably
    resolve this by using some java to move the file to a directory which utl_file can see.Another alternative is to specify a location on then database server where all file attachments MUST be copied to and the define and Oracle DIRECTORY (CREATE OR REPLACE DIRECTORY [dir_name] AS '/dir/name/on/files/system';) that references this location. When you attach a file to an email, then you only have to refer to the DIRECTORY for the file location.
    Just my 2 cents on the topic. :-)
    Craig...

  • How to send mail from servlets

    m having troubles sending mail from servlets...
    how do you use the SimpleMailUser object needed in the session?
    a sample code on this would be of great help, thanks!

    <html>
    <body bgcolor="white">
    <font size=5 color="black">
    <%@ page import="javax.servlet.http.HttpUtils" %>
    <%@ page import="java.util.*" %>
    <%@ page import = "java.sql.*" %>
    <%@ page import = "java.io.*" %>
    <%@ page import= "sun.net.smtp.SmtpClient" %>
    <%
         String from,to,subject,msgbody,serverName;
         try
    from = request.getParameterValues("from")[0];
    to = request.getParameterValues("to")[0];
    subject = request.getParameterValues("subject")[0];
    msgbody = request.getParameterValues("msgbody")[0];
    serverName = request.getParameterValues("server")[0];
         catch (Exception e)          // Generally Speaking, an Error getting one of these
                                       // Values means that it wasnt passed in; inform the user
              out.println("You must call this JSP from this ");
              out.println("<A href=\"FormMail.htm\"> form</A>.<BR>");
              out.flush();return;
    %>
    Hold On A Moment while I try to Send Your Mail... <BR>
    <%
         out.flush();
         // Here are the real guts of the mail sending
         try
         sun.net.smtp.SmtpClient sm = new sun.net.smtp.SmtpClient(serverName);
         sm.from(from);
         sm.to(to);
         PrintStream msg = sm.startMessage();
         msg.println("To: ");     // Note dont use + for Performance
         msg.println(to);
         msg.println("Subject: ");
         msg.println(subject);
         msg.println();
         msg.println(msgbody);
         msg.println("==============");
         msg.print("This mail brought to you by JSP MAIL..from a user at IP ");
         msg.println(request.getRemoteHost());
         sm.closeServer();
         out.println("Your Mail Has Been Sent!");
         catch (Exception e)
              out.println("The mail couldn't be sent, probably because the mailhost wasnt set correctly.<BR> ");
              out.println("The error message I am getting is: ");
              out.println(e.getMessage());
    %>
    <BR>
    <BR>
    Click here to send another!

  • Send mail from my oracle database

    I want to send mail from my oracle database.
    I have followed the steps below:
    1> Run utlmail.sql & prvtmail.plb
    2>set smtp_out_server parameter
    3>To send mail, execute utl_mail.send(sender=>'',recipients=>'',message=>'ABC');
    My concept is to provide smtp/mail server ip & port in smtp_out_server parameter's value.
    But One person said that oracle database server can make itself as a smtp server.So that we can assign database server ip & port in smtp_out_server parameter's value.We have to just on the smtp service in oracle database itself.There is no requirement of smtp/mail server ip & port.Is it true?How can we do that?
    In google to Add an SMTP Service,the document said in the 1st line that on the Services tab on the left, select a Process tree node (for example, the default Oracle Enterprise Gateway).
    I am sorry to say that I did not find that.Anyone can help me please?
    Please reply anyone.

    979620 wrote:
    But One person said that oracle database server can make itself as a smtp server.So that we can assign database server ip & port in smtp_out_server parameter's value.We have to just on the smtp service in oracle database itself.There is no requirement of smtp/mail server ip & port.Is it true?How can we do that?Not true - I cannot recall ever seeing a native service in the Oracle database that acts as a SMTP server.
    PL/SQL code can only create and use tcp client sockets via UTL_TCP. A tcp server socket is needed for a SMTP server.
    The Oracle database also does not listen and accept incoming client tcp connections - the Oracle Listener does that (separate process/layer).
    The Oracle database instance registers the services it has available with the Listener. There are 3 basic type of services that the instance will register:
    - dedicated services (supporting Oracle client connections)
    - dispatchers for shared services (supporting Oracle client connections)
    - http/ftp services (supporting XMLDB WebDav, WebService and EPG servlets access for web based clients)
    There is no support for a SMTP service.
    You can install SMTP server s/w on the same platform as the Oracle server s/w. You may even (via Oracle Collaboration services I think) use the Oracle database for mail drops and mail boxes (storage). But I have not yet seen an actual SMTP server running as PL/SQL or Java code inside a database instance as a database server process.

  • 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

  • Send mail from database

    Hi, i am trying to send mail from database i have create a database in mysql and the program will retreive the email and send it to the person.
    I have set the classpath in my window 98.
    But still cannot run
    Below is my source code;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.net.*;
    import java.text.*;
    import java.io.*;
    public class Emailer
         public static void sendMessage( String title,
         String email1,String email2, String message1)
         throws Exception     
    try
    String host = "192.9.201.28";
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    Session session = Session.getInstance(props, null);
    Message msg = new MimeMessage(session);
         InternetAddress [] address = null;
    address = InternetAddress.parse(email1);
         InternetAddress [] ccaddress = null;
         ccaddress = InternetAddress.parse(email2);
         String mailsenderaddr = "[email protected]";
         msg.setFrom(new InternetAddress(mailsenderaddr));
         msg.setRecipients(Message.RecipientType.TO, address);
         System.out.println(email1);
         msg.setRecipients(Message.RecipientType.BCC, ccaddress);
         System.out.println(email2);
         msg.setSubject(title);
         System.out.println(title);
         msg.setSentDate(new java.util.Date());
         msg.setText(message1);
         System.out.println(message1);
         Transport.send(msg);
    System.out.println("Mesage Send");
    catch (MessagingException mex)
    System.out.println("msg err:"+mex);
         public static void main(String[] argv) throws Exception     
         try {
         System.out.println("Loading Driver (with Class.forName)");
         Class.forName ("org.gjt.mm.mysql.Driver");
         System.out.println("Getting Connection");
         Connection conn = DriverManager.getConnection (
         "jdbc:mysql://192.9.201.40/test?user=testid&password=testpwd");     // user, passwd
         System.out.println("Creating Statement");
         Statement stmt = conn.createStatement();
         System.out.println("Executing Query");
         ResultSet rs = stmt.executeQuery("SELECT * FROM Reminder where Date_Remind='20050406'");
         System.out.println("Retrieving Results");
         int i = 0;
         while (rs.next()) {
              String title = rs.getString("Title");
              String message1 = rs.getString("Message");
              String date_remind = rs.getString("Date_Remind");
              String email1 = rs.getString("Email1");
              String email2= rs.getString("Email2");
    System.out.println("ROW " + ++i + ": " +
    title + "; " message1 ";" + date_remind + "; " + email1+ ";" + email2+ ";");
              sendMessage ( title, email1,email2, message1);
              rs.close();          // All done with that resultset
              stmt.close();     // All done with that statement
              conn.close();     // All done with that DB connection
         } catch (ClassNotFoundException e) {
                   System.out.println("Can't load driver " + e);
         } catch (SQLException e) {
              System.out.println("Database access failed "+ e);
    But there are still error in the following:
    msg error: javax.mail.NoSuchProviderException: No provider for SMTP
    Please help..
    Thank you

    Can you print the error message your getting. Are you able to print date_reminder, email1, email2 from your db.

  • 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

  • How to send mails from Oracle database

    Hi All,
    I want to send a mail from my oracle database once my store
    procedure runs successfully or fails.
    How can i do this.
    what are the preliminary modules of Oracle which need to be
    active for me to do so.
    If any once can also mention about any links that give
    information about the same it will be very helpful for me.
    Thanks and Regards
    Srinivas Chebolu

    CREATE OR REPLACE PROCEDURE SEND_MAIL_TCP(
    msg_from varchar2 := '[email protected]',
    msg_to varchar2,
    msg_subject varchar2 := 'E-Mail message from your database',
    msg_text varchar2 := '' )
    IS
    c utl_tcp.connection;
    rc integer;
    BEGIN
    c := utl_tcp.open_connection('1.17.0.218', 25); -- open the SMTP
    port 25 on local machine
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'HELO localhost');
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from);
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to);
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'DATA'); -- Start message body
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'Subject: '||msg_subject);
    rc := utl_tcp.write_line(c, '');
    rc := utl_tcp.write_line(c, msg_text);
    rc := utl_tcp.write_line(c, '.'); -- End of message body
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'QUIT');
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    utl_tcp.close_connection(c); -- Close the connection
    EXCEPTION
    when others then
    raise_application_error(-20000,'Unable to send e-mail message
    from pl/sql');
    END;
    show errors
    exec send_mail(msg_to =>'[email protected]');
    exec send_mail(msg_to
    =>[email protected]',msg_text=>'Look Yaar, I can send
    mail from plsql');

Maybe you are looking for