Hello.
It's my first message on this forum.
I am using Oracle 9i with Developer 6i.
How can i make that by pressing a button to send an e-mail to a certain person with a predefined text merged with some changing variables (like name, cost)?
Thanks.
Hi,
Following procedure will help you to send text as well attachements.
This process makes use of SAMTP to send mails.
/* ** ****************************************************************************************** ** *
** DESCRIPTION OF SCRIPT : THIS PROCESS IS FOR SENDING MAIL WITH THE ATTACHMENT * ** ****************************************************************************************** ** */
CREATE OR REPLACE PROCEDURE MAIL_FILE( SUBJECT IN VARCHAR2,
MESSAGE IN VARCHAR2,
MAX_SIZE IN NUMBER DEFAULT 9999999999,
FILENAME1 IN VARCHAR2 DEFAULT NULL,
FILENAME2 IN VARCHAR2 DEFAULT NULL,
FILENAME3 IN VARCHAR2 DEFAULT NULL,
RETURN_DESC OUT VARCHAR2) IS
L_SMTP_SERVER VARCHAR2(20); /** TO STORE THE IP ADDRESS OF THE SMTP SERVER **/
L_SMTP_SERVER_PORT NUMBER; /** TO STORE THE SMTP PORT OF THE SMTP SERVER **/
L_DIRECTORY_NAME VARCHAR2(200); /** TO STORE THE PATH / DIRECTORY NAME OF THE FILE **/
L_FILE_NAME VARCHAR2(100); /** TO STORE THE FILENAME **/
L_LINE VARCHAR2(1000); /** TO STORE THE CONTENTS OF THE LINE READ FROM THE FILE **/
CRLF VARCHAR2(2):= CHR(13) || CHR(10);
L_MESG VARCHAR2(32767); /** TO STORE THE MESSAGE **/
CONN UTL_SMTP.CONNECTION; /** SMTP CONNECTION VARIABLE **/
L_MSG_TO VARCHAR2(2000); /** TO STORE THE LIST OF RECIPEINTS **/
L_SENDER_NAME VARCHAR2(200); /** TO STORE THE NAME OF THE SENDER **/
TYPE VARCHAR2_TABLE IS TABLE OF VARCHAR2(200) INDEX BY BINARY_INTEGER;
FILE_ARRAY VARCHAR2_TABLE; /** AN ARRAY TO STORE THE FILE NAMES **/
I BINARY_INTEGER; /** ARRAY INDEX **/
L_FILE_HANDLE UTL_FILE.FILE_TYPE; /** FILE POINTER **/
L_SLASH_POS NUMBER; /** TO STORE THE POSITION OF \ IN THE FILE NAME **/
L_MESG_LEN NUMBER; /** TO STORE THE LENGHT OF THE MESSAGE **/
ABORT_PROGRAM EXCEPTION; /** USER DEFINED EXCEPTION **/
MESG_LENGTH_EXCEEDED BOOLEAN := FALSE; /** BOOLEAN VARIABLE TO TRAP IF THE MESSAGE LENGHT IS EXCEEDING **/
RETURN_DESC1 VARCHAR2(2000); /** VARIABLE TO STORE THE ERROR MESSAGE. TO BE RETURNED TO THE CALLING PROGRAM **/
/*** CURSOR TO SELECT THE RECIPEINTS AND MARK A COPY TO THE SENDER AS WELL ***/
CURSOR RECIPIENT_CUR IS
SELECT VAL
FROM MISC
WHERE KEY1 = 'EMAIL'
AND (KEY2 = 'RECIPIENT EMAIL'
OR KEY2 = 'SENDER EMAIL');
/***
** THIS PROCEDURE FETCHES THE VALUES FOR MISCELLANEOUS PARAMETERS
***/
PROCEDURE FETCH_MISC IS
BEGIN
RETURN_DESC1 := '11 - E: PARAMETER NOT MAINTAINED IN MISC FOR AM_KEY1 = SMTP SERVER. ';
L_SMTP_SERVER := PACKAGE.GET_PVAL('SMTP SERVER');
RETURN_DESC1 := '22 - E: PARAMETER NOT MAINTAINED IN MISC FOR AM_KEY1 = SMTP PORT. ';
L_SMTP_SERVER_PORT := PACKAGE.GET_PVAL('SMTP PORT');
RETURN_DESC1 := '33 - E: PARAMETER NOT MAINTAINED IN MISC FOR AM_KEY1 = TICKET_EMAIL AND KEY2 =SENDER EMAIL. ';
L_SENDER_NAME := PACKAGE.GET_PVAL('TICKET_EMAIL','SENDER EMAIL');
RETURN_DESC1 := '10 - E: THERE WAS AN ERROR IN OPENING CONNECTION. ';
CONN:= UTL_SMTP.OPEN_CONNECTION( L_SMTP_SERVER, L_SMTP_SERVER_PORT ); /** OPEN CONNECTION ON THE SERVER **/
UTL_SMTP.HELO( CONN, L_SMTP_SERVER ); /** DO THE INITIAL HAND SHAKE **/
UTL_SMTP.MAIL( CONN, L_SENDER_NAME );
RETURN_DESC1 := '20 - E: THERE WAS AN ERROR IN CREATING RECEIPIENTS. ';
FOR L_RECIPIENT_CUR_REC IN RECIPIENT_CUR /** LOOP FOR MULTIPLE RECEIPEINTS **/
LOOP
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.