Db2 – Sending a mail using DB2’s Proceude UTL_MAIL

database-maildb2

I'm trying to send mail from DB2 using the procedure UTL_MAIL.
I'm using the DB2 Express Edition 10.1.
First I was getting the error of SMTP Server.
After using the below command,

update admin cfg using smtp_server LOCALHOST

I am using the following command to send the mail:

CALL UTL_MAIL.SEND('test@mycomp.com','myid@hotmail.com',NULL,NULL,'Test Email','Test body')

Now I am getting the following error:

SQL1336N The remote host "" was not found. SQLSTATE=08001

I searched a lot and found out that I must CATALOG the server details.

Can anyone please help me regarding this?

Best Answer

Based on what you are trying to do you would want to set up the STMP server at the database level rather than the DAS level. You set it up at the DAS level if you want DB2 to email alerts to you. See the Information Center here.

You set it up at the database level if you want to use the UTL_MAIL module as you are wishing to use.

You would need to do the following:

db2 connect to mydb -- or whatever your database name is.
db2 update db cfg using smtp_server '<server or ip>:<port>' 
-- you can have a list of smtp servers if you want, just use a comma between them.
db2 connect reset

This setting takes affect immediately. Please see Information Center for more details.

Related Question