Sometimes it’s needed to send an email using PL/SQL. This can be done with few lines of code pasted below. The variables $server.address, $domain, $sender_email, $recipient_email should be replaced with the relevant information.


DECLARE
l_retVal INTEGER;
v_connection UTL_SMTP.connection;
BEGIN
v_connection := UTL_SMTP.open_connection('$server.address');
UTL_SMTP.helo(v_connection, '$domain');
UTL_SMTP.mail(v_connection, '$sender_email');
UTL_SMTP.rcpt(v_connection, '$recipient_email');
UTL_SMTP.open_data(v_connection);
UTL_SMTP.write_data(v_connection, 'From: $sender_email' || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, 'To: $recipient_email' || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, 'The Subject!' || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, 'The Content!' || UTL_TCP.crlf);
UTL_SMTP.close_data(v_connection);
UTL_SMTP.quit(v_connection);
EXCEPTION
WHEN OTHERS THEN
null;
END;

Did it work for you?




Other Posts
Comments

Name (required)

Email (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Share your wisdom