Sending email from Procedure

Database

Sending email from Procedure

Hi Experts,

We have a requirement to send email to set of users on successful execution of a Teradata procedure.
Is there a way to send email from Teradata procedure or any other way to achieve this functionality.
Procedure is getting called from Java. We prefer to send email frome either Teradata directly or from UNIX box. But not sure procedure can call a UNIX shell file.

Appreciate your valuable opinion in this.

Thanks
Raviraj
3 REPLIES
Enthusiast

Re: Sending email from Procedure

Please try this out.

.OS mail -s "SUCCESSFUL EXECUTION OF PROCEDURE." ABCD@gmail.com xyz@gmail.com
Enthusiast

Re: Sending email from Procedure

".OS" is a BTEQ command. I would not expect that to work in a stored procedure.

You can write an external stored procedure in Java or C, which could call any function that is supported by the language and platform, but email services are not usually running on Teradata nodes.
Enthusiast

Re: Sending email from Procedure

If you are running on Linux/ Unix, you can call your stored procedure from bteq, then use the .OS command to send the messages. If you want to add some sort of details from the database, your stored procedure would have to create the details in a table; then use bteq export to send these to a file. The file can be the body of the email which is then sent to the mail command on Unix/ Linux. In this case the export and mail must be in bteq after calling the proc.
As the commands come from bteq on your home server (the server you sign onto to run scripts), not from a database node, it works fine.

If you are using Windows, you would need to use something like C++ and the mapi interface to create messages. It is very messy though!
I have never used it on mainframes. The ".OS mail" command will not run on mainframes, but there is similar functionality if you really need it.