Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email
![](https://support.oracle.com/epmos/adf/images/t.gif)
In this Document
APPLIES TO:PL/SQL - Version 9.2.0.8 and laterInformation in this document applies to any platform. ***Checked for relevance on 13-May-2014*** SYMPTOMSWhen trying to send email using UTL_SMTP getting following error : ORA-29278: SMTP transient error: 421 Service not available
ORA-06512: at "SYS.UTL_SMTP", line 21 ORA-06512: at "SYS.UTL_SMTP", line 97 ORA-06512: at "SYS.UTL_SMTP", line 139
ORA-29279: SMTP permanent error
CAUSEThe "ORA-29278: SMTP transient error: 421 Service not available" error indicates that the problem is not with the UTL_SMTP package SOLUTIONYou first have to check whether you are able to contact the email server without involving ORACLE. For example use the following telnet procedure to see whether the mail server is reachable from the Database server: Note: The information presented here does not apply to TLS/SSL connections .
a) Start a telnet session to the SMTP server's communication port. (The default port for SMTP is 25)
$telnet <smtp servername as used utl_smtp package> 25 A telnet session should open with a response from smtp: For eg : response from smtp ---> 220 ukxxx1 Sendmail SMI-8.6/SMI-SVR4 ready at Thu, 16 Sep 1999 15:14:25 +0100 b) Now introduce the client machine to the server by typing: helo domain (The correct spelling is helo - not hello) c) Tell the SMTP Gateway who the test email is coming from by typing: -------> mail from: emailid@domain For eg : A response from smtp ---> 250 emailid@domain... Sender ok d) Tell the SMTP Gateway who to send the test email to by typing: --------> rcpt to: emailid@domain For eg : A response from smtp ---> 250 emailid@domain... Recipient ok e) Tell the SMTP Gateway what type of information is being sent by typing: -------> data A response from smtp ---> 354 Enter mail, end with "." on a line by itself f) Enter the test message and remember to close the email with a dot "." Type ---> Subject: SMTP Test Hello this is an smtp test for EM. . A response from smtp ---> 250 PAA15913 Message accepted for delivery g) End the SMTP connection session by typing: --------> quit response from smtp ---> 221 ukxxx1 closing connection The connection has been terminated.
Note : Please change the smtp server name in line number 6 and 7 in procedure TESTMAIL. Note: If the below code fails again with the same error , then use IP Address instead of Mail server name in line number 6 and 7.
OR Make the hostname entry in the /etc/hosts file so that it is properly resolved to an IP address
CREATE OR REPLACE PROCEDURE TESTMAIL(fromm VARCHAR2,too VARCHAR2,sub VARCHAR2,body VARCHAR2,port NUMBER)
IS objConnection UTL_SMTP.CONNECTION; vrData VARCHAR2(32000); BEGIN objConnection := UTL_SMTP.OPEN_CONNECTION('<user smtp server name or ip address>',PORT); UTL_SMTP.HELO(objConnection, '<user smtp server name or ip address>'); UTL_SMTP.MAIL(objConnection, fromm); UTL_SMTP.RCPT(objConnection, too); UTL_SMTP.OPEN_DATA(objConnection); UTL_SMTP.WRITE_DATA(objConnection, 'From: '||fromm || UTL_TCP.CRLF); UTL_SMTP.WRITE_DATA(objConnection, 'To: '||too || UTL_TCP.CRLF); UTL_SMTP.WRITE_DATA(objConnection, 'Subject: ' || sub || UTL_tcp.CRLF); UTL_SMTP.WRITE_DATA(objConnection, 'MIME-Version: ' || '1.0' || UTL_tcp.CRLF); UTL_SMTP.WRITE_DATA(objConnection, 'Content-Type: ' || 'text/html;'); UTL_SMTP.WRITE_DATA(objConnection, 'Content-Transfer-Encoding: ' || '"8Bit"' || UTL_TCP.CRLF); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF||'<HTML>'); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF||'<BODY>'); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF||'<FONT COLOR="red" FACE="Courier New">'||body||'</FONT>'); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF||'</BODY>'); UTL_SMTP.WRITE_DATA(objConnection,UTL_TCP.CRLF||'</HTML>'); UTL_SMTP.CLOSE_DATA(objConnection); UTL_SMTP.QUIT(objConnection); EXCEPTION WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN UTL_SMTP.QUIT(objConnection); DBMS_OUTPUT.PUT_LINE(SQLERRM); WHEN OTHERS THEN UTL_SMTP.QUIT(objconnection); DBMS_OUTPUT.PUT_LINE(SQLERRM); END TESTMAIL; / DECLARE
Vdate Varchar2(25); BEGIN Vdate := to_char(sysdate,'dd-mon-yyyy HH:MI:SS AM'); TESTMAIL('xxx.xxx@xxx.com', 'xxx.xxx@xxx.com', 'TESTMAIL','This is a UTL_SMTP-generated email at '|| Vdate,25); END; /
Collaborate with and learn from your Peers, Industry Experts and Oracle Support Product Specialists using My Oracle Support Community. Join us here: REFERENCESNOTE:74269.1 - How to Test an SMTP Mail Gateway From a Command Line InterfaceNOTE:1559609.1 - ORA-29278: SMTP Transient Error: 452 4.4.5 Insufficient Disk Space |