Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use UTL_SMTP to send from a Hotmail account

PhilMan2Jun 15 2023

I'm using Oracle 21.c. I've had code in place for years that sends batch Emails using UTL_SMTP. The procedure works fine when I send it from an Email account I create on my Web Server.

I have a request from a user t1o send from a Hotmail account, but I can't get my procedure to work. I receive the error: ORA-29279: SMTP permanent error: 504 5.7.4 Unrecognized authentication type [BLAPR03CA0121.namprd03.prod.outlook.com 2023-06-15T19:20:40.696Z 08DB6D4B19623242]

The following test code works fine when I send an Email from a mail account in my web domain, but fails when I adjust the Hostname, Port, Username and Password to send from a Hotmail (Outlook) account.

DECLARE
l_smtp_hostname varchar2(1024);
l_smtp_port number;
l_smtp_username varchar2(1024);
l_smtp_password varchar2(1024);
l_encoded_username varchar2(1024);
l_encoded_password varchar2(1024);
l_smtp_conn utl_smtp.connection;
BEGIN
l_smtp_hostname := 'smtp.office365.com';
l_smtp_port := 587;
l_smtp_username := 'my_username@hotmail.com';
l_smtp_password := 'my_password';
-- Encode l_smtp_username and l_smtp_password
l_encoded_username := UTL_RAW.cast_to_varchar2
(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(l_smtp_username)));
l_encoded_password := UTL_RAW.cast_to_varchar2
(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(l_smtp_password)));
-- Define the connection
l_smtp_conn := UTL_SMTP.open_connection(l_smtp_hostname, l_smtp_port);
utl_smtp.ehlo(l_smtp_conn, l_smtp_hostname);--DO NOT USE HELO
--authenticate to the server using the encoded username and password
utl_smtp.command(l_smtp_conn, 'AUTH', 'LOGIN');
utl_smtp.command(l_smtp_conn, l_encoded_username);
utl_smtp.command(l_smtp_conn, l_encoded_password);
-- Close the open connection
utl_smtp.quit(l_smtp_conn);
END;

I don't know what is meant by “Unrecognized authentication type”. Thanks for looking at this.

Comments
Post Details
Added on Jun 15 2023
3 comments
707 views