<%@ page language="PL/SQL" %> <%@ page errorPage="Sm_Error_Page.psp" %> <%@ plsql procedure="send_email" %> <%@ plsql parameter="p_from" type="VARCHAR2" %> <%@ plsql parameter="p_to" type="VARCHAR2" %> <%@ plsql parameter="p_subject" type="VARCHAR2" %> <%@ plsql parameter="p_contents" type="VARCHAR2" %> <%! /** Overview : This PSP is part of the send email sample. The PSP receives the inputs for the email. The email is sent using the UTL_SMTP package. Any error that happens during the operation will be returned in an Error Page. Modification History: Person Date Comments ------------------------------------------------------------- V.Srinivasan 16-AUG-2000 Initial Sample **/ %> <%! /* Constant declarations */ -- Please change the following MAIL_HOST and MAIL_PORT values appropriate -- to your environment MAIL_HOST VARCHAR2(50) := 'yoursmtpserver.yourdomainname'; MAIL_PORT NUMBER(4) := 25; SUCCESS_VALUE NUMBER(4) := 250; /* Variable Declarations */ l_mail_conn utl_smtp.connection; l_vrfy_msg utl_smtp.reply; l_message VARCHAR2(2000); %> <% BEGIN /* Open a connection to an SMTP server */ l_mail_conn := utl_smtp.open_connection(MAIL_HOST, MAIL_PORT); /* Perform initial handshaking with the SMTP server after connecting */ utl_smtp.helo(l_mail_conn, MAIL_HOST); /* Verify the validity of the sender address */ l_vrfy_msg := utl_smtp.vrfy(l_mail_conn, p_from); IF l_vrfy_msg.code <> SUCCESS_VALUE THEN RAISE_APPLICATION_ERROR (-20001,'Invalid sender address'); END IF; /* Verify the validity of the destination address */ l_vrfy_msg := utl_smtp.vrfy(l_mail_conn, p_to); IF l_vrfy_msg.code <> SUCCESS_VALUE THEN RAISE_APPLICATION_ERROR (-20002,'Invalid recipient address'); END IF; /* Initiate a mail transaction with server */ utl_smtp.mail(l_mail_conn, p_from); /* Specify the recipient of the email message */ utl_smtp.rcpt(l_mail_conn, p_to); /* Specify the body of the email message along with Subject. RFC 821 standard requires to send the Subject along with body of message and separated by line feed */ l_message := 'Subject:'||p_subject||chr(10)||p_contents; utl_smtp.data(l_mail_conn, l_message); /* Terminate the SMTP session and disconnect from the server */ utl_smtp.quit(l_mail_conn); EXCEPTION WHEN OTHERS THEN IF SQLCODE IN (-20001, -20002, -20003) THEN RAISE; ELSE RAISE_APPLICATION_ERROR(-20004,SQLERRM); -- Handle the error END IF; END; %> PSP Sample - Email Acknowledgement

Mail has been successfully sent to <%= p_to %>

Send Email