Home » SQL & PL/SQL » SQL & PL/SQL » sending email thru PL/SQL ..
sending email thru PL/SQL .. [message #184574] Thu, 27 July 2006 02:24 Go to next message
frank.svs
Messages: 162
Registered: February 2006
Senior Member
Hi frns,

I have written a sample a stored procedure to send a somple mail which says "Good luck ..".
I am able to successfully send an email but i am not able give the Subject Line while sending an email.
Can anyone help me out in giving the subject line.

create or replace procedure p1
as
conn utl_smtp.connection;
begin
conn := utl_smtp.open_connection('smtp.xxx.com',25);
utl_smtp.helo(conn, 'smtp.xxx.com');
utl_smtp.mail(conn,'sender@companyname.com');
utl_smtp.rcpt(conn, 'frank.svs@gmail.com');
utl_smtp.open_data(conn);
utl_smtp.write_data(conn, UTL_TCP.CRLF || 'Good Luck .......');
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
dbms_output.put_line('*** Mail has been Sucessfully sent to the intended recepient ***');
EXCEPTION
WHEN others THEN
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
dbms_output.put_line('!!! ERROR OCCURED !!!');
end;
/



Thanks and Regards,
frank


Re: sending email thru PL/SQL .. [message #184586 is a reply to message #184574] Thu, 27 July 2006 02:57 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
From the doumentation in the package header of UTL_SMTP (what an odd place to think of looking) comes this sample piece of code.
Spotting the exact line that sets the Subject is left as an exercise for the reader.

 BEGIN
   c := utl_smtp.open_connection('smtp-server.acme.com');
   utl_smtp.helo(c, 'foo.com');
   utl_smtp.mail(c, 'sender@foo.com');
   utl_smtp.rcpt(c, 'recipient@foo.com');
   utl_smtp.open_data(c);
   send_header('From',    '"Sender" <sender@foo.com>');
   send_header('To',      '"Recipient" <recipient@foo.com>');
   send_header('Subject', 'Hello');
   utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!');
   utl_smtp.close_data(c);
   utl_smtp.quit(c);
 EXCEPTION
Previous Topic: How to write a data file (simple flat file) using PL/SQL List
Next Topic: Need Command
Goto Forum:
  


Current Time: Thu Dec 08 08:38:53 CST 2016

Total time taken to generate the page: 0.16040 seconds