Facing issues with sending email using UTL_SMTP with office 365
telnet smtp.office265.com 587
Sending email from telnet
telnet smtp.office365.com
220 MRXP264CA0003.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 5 Feb 2024 06:48:34 +0000
helo
250 MRXP264CA0003.outlook.office365.com Hello [62.215.133.29]
mail from: dbakw@outlook.com
451 5.7.3 STARTTLS is required to send mail [MRXP264CA0003.FRAP264.PROD.OUTLOOK.COM 2024-02-05T06:48:51.707Z 08DC25AFB6478F6B] <<<<<
Connection to host lost. <<<<<<<<<<<
while Sending EMail from UTL_SMTP,
ORA-29278: SMTP transient error: 451 5.7.3 STARTTLS is required to send mail [DX0P273CA0017.AREP273.PROD.OUTLOOK.COM 2024-02-05T07:20:43.555Z 08DC259CFA7B05BB]
ORA-06512: at "SYS.UTL_SMTP", line 57
ORA-06512: at "SYS.UTL_SMTP", line 140
ORA-06512: at "SYS.UTL_SMTP", line 476
ORA-06512: at "HRM.SEND_MAIL", line 12
ORA-06512: at line 19
Use below code to send email using UTL_SMTP
DECLARE
crlf varchar2(2) := UTL_TCP.crlf;
connection UTL_SMTP.connection;smtpServer varchar2(100) := 'smtp.office365.com';
emailSubject varchar2(100) := 'Test Email Using SMTP with office 365';smtpUsername varchar2(100) := 'dbakw@outlook.com';
smtpPassword varchar2(100) := 'PasswordFor dbakw Email user';emailDestination varchar2(100) := 'dbakw@gmail.com';
walletPath varchar(100) := 'file:C:\oracle\wallet\wallet7';
walletPassword varchar2(100) := 'xxxxx';BEGIN
connection := UTL_SMTP.open_connection(
host => smtpServer,
port => 587,
wallet_path => walletPath,
wallet_password => walletPassword,
secure_connection_before_smtp => FALSE);
UTL_SMTP.ehlo(connection, smtpServer);
UTL_SMTP.starttls(connection);
UTL_SMTP.ehlo(connection, smtpServer);
UTL_SMTP.auth(
c => connection,
username => smtpUsername,
password => smtpPassword,
schemes => utl_smtp.all_schemes);
UTL_SMTP.mail(connection, smtpUsername);
UTL_SMTP.rcpt(connection, emailDestination);
UTL_SMTP.open_data(connection);
UTL_SMTP.write_data(connection, 'Date: ' || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || crlf);
UTL_SMTP.write_data(connection, 'From: ' || smtpUsername || crlf);
UTL_SMTP.write_data(connection, 'Subject: ' || emailSubject || crlf);
UTL_SMTP.write_data(connection, 'To: ' || emailDestination || crlf);
UTL_SMTP.write_data(connection, '' || crlf);
UTL_SMTP.write_data(connection, 'Test Email from database. ' || crlf);
UTL_SMTP.close_data(connection);
UTL_SMTP.quit(connection);
END;
/
No comments:
Post a Comment