Home » SQL & PL/SQL » SQL & PL/SQL » Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 (O/S:Windows 8; Product: Oracle; version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)
Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629049] Tue, 02 December 2014 14:01 Go to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I have a procedure(private and not declared in package specs) called p_sendmail and this should raise an error message and pass that message to the calling procedure so that it can be shown on a web page. I am just unable to do that when I pass an invalid email id. The page just errors out with a runtime error saying:

Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 <balbhablh@abcd.ca>... User unknown
ORA-06512: at "STANJORE.BWAKPLNS", line 401
ORA-06512: at "STANJORE.BWAKPLNS", line 1106
ORA-06512: at "STANJORE.BWAKPLNS", line 1248
ORA-06512: at line 33


The code for p_sendmail is as follows:

-- Local variable
   
    CRLF        CONSTANT  VARCHAR2(2) := CHR(13) || CHR(10);
    p_err_message1	  VARCHAR2(100);

-- --------------------------------------------------------------------------------
-- FORWARD DECLARATIONS
-- -----------------------------------------------------------------------------
  PROCEDURE p_sendmail(p_sender_email  IN VARCHAR2,
                      p_from          IN VARCHAR2,
                      p_to            IN VARCHAR2,
                      msg_subject     IN VARCHAR2 DEFAULT NULL,
                      p_msg_body      IN LONG DEFAULT NULL
		      );


PROCEDURE p_sendmail(p_sender_email  IN VARCHAR2,
                      p_from          IN VARCHAR2,
                      p_to            IN VARCHAR2,
                      msg_subject     IN VARCHAR2 DEFAULT NULL,
                      p_msg_body      IN LONG DEFAULT NULL
                      ) is
      v_to_list     LONG;
      v_cc_list     LONG;
      v_bcc_list    LONG;
      v_date        VARCHAR2(255) DEFAULT TO_CHAR(SYSDATE, 'DD MON YYYY HH24:MI:SS PM');
      
      g_mail_conn            UTL_SMTP.CONNECTION;
      SMTP_HOST   CONSTANT  VARCHAR2(256) := 'smtp-abc.defg.ca';
      SMTP_PORT   CONSTANT  PLS_INTEGER   := 25;

   BEGIN

      g_mail_conn := UTL_SMTP.OPEN_CONNECTION(SMTP_HOST, SMTP_PORT);

      UTL_SMTP.helo(g_mail_conn, SMTP_HOST);
      UTL_SMTP.mail(g_mail_conn, p_sender_email);   
      UTL_SMTP.rcpt(g_mail_conn, p_to);   
      UTL_SMTP.open_data(g_mail_conn );     
      UTL_SMTP.write_data( g_mail_conn, '' || CRLF);
      UTL_SMTP.write_data(g_mail_conn, p_msg_body);
      UTL_SMTP.close_data(g_mail_conn );
      UTL_SMTP.quit(g_mail_conn);

EXCEPTION

			WHEN utl_smtp.transient_error THEN
			     RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					 --DBMS_OUTPUT.put_line('TransientError: Invalid Operation as service may not be available.');
					 					 
			WHEN utl_smtp.permanent_error THEN
					 RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					 --DBMS_OUTPUT.put_line('Permanent Error: The email id entered is either invalid or recepients mail box is full.');
					 --p_errmessage:=SQLERRM;
					 
			WHEN others THEN
					RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					
			
			IF SQLERRM IS NOT NULL THEN
					 		p_err_message1:=SQLERRM;
			ELSE
			  	 		p_err_message1:=NULL;
			END IF;
					
END p_sendmail;


p_sendmail(p_sender_email => 'stanjore@someemailid.ca',   --- Send Email to the Donor     
	   p_from => 'PLEDGING <stanjore@someemailid.ca>', 
	   p_to =>   v_store_email_address,
	   p_msg_subject => 'Anonymous User', 
	   p_msg_body => 'Thank you'  ||  
	   CRLF || 
	  'The email confirms that we have received your pledge' ||  
	  CRLF || 
	  CRLF || 
	 ' Name:         ' || v_full_name ||
	  CRLF || 
	 'Temporary  ID: ' || v_azbwccp_id ||
	  CRLF || 
	 'Reference Number:   ' || MTID ||
	 CRLF || 
	 ' Amount:      ' || to_number(campaign_desg_amt1) ||
	 CRLF || 
	' Campaign:    ' || campaign ||
	 CRLF || 
	' Designation: ' || adbdesg_rec.adbdesg_name ||
	 CRLF || 
	' Type:        ' || atvpldg_rec.atvpldg_desc ||
	 CRLF || 
	' Duration:    ' || atvpdur_rec.atvpdur_desc ||
	 CRLF || 
	 ' Frequency:   ' || atvfreq_rec.atvfreq_desc ||
	 CRLF || 
	 ' Start Date:  ' || bill_date2 ||
	 CRLF || 
	 CRLF || 						                     
	 'Your pledge is being processed.' ||
	CRLF || 			
	'In the meantime, should you wish to amend this transaction, please contact us ' ||
	 CRLF || 	
	 CRLF || 				                     					                     
	 'Thank you for your support.' ||
	 CRLF || 
	 CRLF || 
	 CRLF || 
	 CRLF || 
	 '*** This is an automated message system. Please do not respond to this e-mail. *** '
        );



--This is where I am trying to bring it back and show it to the user on the page.

IF p_err_message1 is NOT NULL THEN
	                     	 	msg_text := '<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The email entered is an invalid one.Please enter a correct one;' ;
	                     END IF;


I opened the file in VI editor and looked at the line numbers but could not decipher it. The only thing I feel that is wrong is I am unable to propogate the error message.

Based on what Oracle and others have said RAISE_APPLICATION_ERROR passes the message from the backend to non oracle front end. So where is that I am going wrong or what is that I am doing wrong. Can any one please help?

Once again many thanks in advance.

[Updated on: Tue, 02 December 2014 14:05]

Report message to a moderator

Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629050 is a reply to message #629049] Tue, 02 December 2014 14:25 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

This:
Quote:
			WHEN others THEN
					RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);

is silly, read WHEN OTHERS.
This:
Quote:
			IF SQLERRM IS NOT NULL THEN
					 		p_err_message1:=SQLERRM;
			ELSE
			  	 		p_err_message1:=NULL;
			END IF;

places after RAISE_APPLICATIN_ERROR is never executed.

ORA-29279: SMTP permanent error: %s
 *Cause:  A SMTP permanent error occurred.
 *Action: Correct the error and retry the SMTP operation.

Error comes the SMTP server and is outside Oracle which only relays it.
Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629052 is a reply to message #629050] Tue, 02 December 2014 14:32 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
So in that case how do we trap the message and pass it to the front end?

About WHEN OTHERS, yes, I agree and it's also a very bad practice from what I read and heard.However was using it for testing purposes.

[Updated on: Tue, 02 December 2014 14:33]

Report message to a moderator

Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629053 is a reply to message #629052] Tue, 02 December 2014 14:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

If you do not trap the error with an exception handler then it is passed to the caller.

Even for testing purpose do not use it.
What could be the benefit of a code you test and which will not go to production?
Test it as it should be in the end.

[Updated on: Tue, 02 December 2014 14:36]

Report message to a moderator

Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629054 is a reply to message #629053] Tue, 02 December 2014 14:39 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Thanks for pointing it out Michel.

So how do we trap the message that you say Quote:
Error comes the SMTP server and is outside Oracle which only relays it.


Right after raise_application_error, in case I include my if else statements, won't it work? I am on my to try that part too.
Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629055 is a reply to message #629054] Tue, 02 December 2014 14:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Comment (or remove) the whole exception block and you will see the caller gets the error as it needs it.

Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629057 is a reply to message #629055] Tue, 02 December 2014 14:46 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Unfortunately it is not returning it Michel. When I take the exception out and then compile the package it successfully compiles. After which I go to the test web page, enter an invalid email address and the page breaks down/bombs/throws a run time error and it is:

Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 <balbhablh@mtroyal.ca>... User unknown


I am trying to trap the message and then display it to the user via a friendly message saying "invalid email id". can this not be done in Oracle? since you said Quote:
Error comes the SMTP server and is outside Oracle which only relays it.
Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629059 is a reply to message #629057] Tue, 02 December 2014 15:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

1/ The message comes from a caller that also use RAISE_APPLICATION error, remove it.
2/ The application gets the message you posted then it is his application that has to display it in its programming language, this has no more relation with Oracle; Oracle gave you the error, it can't display it.

Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629060 is a reply to message #629057] Tue, 02 December 2014 15:02 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
p_err_message1:=NULL;
EXCEPTION
	p_err_message1:=SQLERRM;				
END p_sendmail;
Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629061 is a reply to message #629059] Tue, 02 December 2014 15:03 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I even tested the example posted on: https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_smtp.htm#i1004292

especially the last EXCEPTION block where he closes the utl_smtp and then raises it yet no luck. I am getting the same run time error that I am seeing.

Are you saying that if UTL_SMTP package fails because of an incorrect email id, Oracle has only power to display or inform the user but no way that message can be displayed to the user? So if this is the case I am out of luck I guess.
Re: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1 [message #629065 is a reply to message #629061] Tue, 02 December 2014 19:39 Go to previous message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
The issue now has been addressed. Everything was ok in the procedure body (i.e. after a few corrections pointed out by Michel Cadot). However some original code that was buggy had to be corrected. Since this was making use of some code using webapps (probably a book on the likes of "Oracle Web Application Programming for PL/SQL Developers") and there were some HTP sytax/code that had to be manipulated to display a friendly error message. So in otherwords it was a PL/SQL package trying to communicate with a front end web page.

Once again thanks a lot to every one helping me out.
Previous Topic: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared
Next Topic: Job Scheduing
Goto Forum:
  


Current Time: Fri Apr 19 19:30:16 CDT 2024