Tuesday 26 July 2011

ORA-29279: SMTP permanent error: 530 5.7.1 Client was not authenticated

I was trying to use utl_smtp to send mails from Oracle database to myself.
This is the PLSQL code I used to do it:

declare
c utl_smtp.connection;
msg_from varchar2(50) := 'Oracle9.2';
mailhost VARCHAR2(30) := 'mail server';
dbserver VARCHAR2(30) := 'db server';
from_eml VARCHAR2(40) := 'from email address';
to_eml VARCHAR2(40) := 'to email address';
begin
c := utl_smtp.open_connection(mailhost, 25); -- SMTP on port 25
utl_smtp.helo(c, dbserver);
utl_smtp.mail(c, from_eml);
utl_smtp.rcpt(c, to_eml
');
UTL_SMTP.open_data (c);
utl_smtp.write_data(c, 'Subject: Your Subject Line Here');
UTL_SMTP.write_data (c, 'This is test message');
UTL_SMTP.close_data (c);
UTL_SMTP.quit (c);
END;
However, when running the above block, it was giving the following error:

ORA-29279: SMTP permanent error: 530 5.7.1 Client was not authenticated
ORA-06512: at "SYS.UTL_SMTP", line 20
ORA-06512: at "SYS.UTL_SMTP", line 98
ORA-06512: at "SYS.UTL_SMTP", line 221
It seems like that the exchange server was not relaying the IP address for the database server to send emails.
To fix it, the system admin managing the exchange added the database server IP address to relay server list.

And it all started to work then.