#
create or replace procedure
testmail
(
fromm varchar2,
too varchar2,
sub varchar2,
body varchar2,
port number
)
is
objConnection utl_smtp.connection;
vrData varchar2(32000);
username varchar2(20) := 'my_user_name';
password varchar2(20) := 'my_password';
begin
objConnection := utl_smtp.open_connection('localhost',25);
utl_smtp.helo(objConnection, 'localhost');
utl_smtp.command(objConnection, 'AUTH LOGIN');
utl_smtp.command(objConnection,utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(username))));
utl_smtp.command(objConnection,utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(password)))); utl_smtp.mail(objConnection, fromm);
utl_smtp.rcpt(objConnection, too);
utl_smtp.open_data(objConnection);
/*** Sending the header information */
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('yourfrom_email@domain.com', 'yourto_email@domain.com', '<subject_line>','This is a UTL_SMTP-generated email at '|| vdate,25);
end;
/