I am struggling to send a mail from plsql. I am using the following code. I am hitting one or other error. Can you plz provide any pointers ?
l_mail_conn := utl_smtp.open_connection( host => l_smtp_host,
port => l_smtp_port,
wallet_path => l_wallet_path,
wallet_password => l_wallet_password,
secure_connection_before_smtp => false);
UTL_SMTP.EHLO(l_mail_conn, L_SMTP_HOST);
-- utl_smtp.starttls(l_mail_conn); // if i enable this line, I get "503 5.5.2 Send hello first" error
-- utl_smtp.command( l_mail_conn, 'auth login'); // I tried this approach as well but I get the same Unrecognized authentication type
-- utl_smtp.command( l_mail_conn, l_mail_username_encoded);
-- utl_smtp.command( l_mail_conn, l_mail_password_encoded);
utl_smtp.auth(l_mail_conn,l_mail_username,l_mail_password,utl_smtp.all_schemes);
UTL_SMTP.mail(l_mail_conn, p_from);
process_recipients(l_mail_conn, p_to);
process_recipients(l_mail_conn, p_cc);
process_recipients(l_mail_conn, p_bcc);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || UTL_TCP.crlf);
UTL_SMTP.write_data(l_mail_conn, 'To: ' || p_to || UTL_TCP.crlf);
IF TRIM(p_cc) IS NOT NULL THEN
UTL_SMTP.write_data(l_mail_conn, 'CC: ' || REPLACE(p_cc, ',', ';') || UTL_TCP.crlf);
END IF;
IF TRIM(p_bcc) IS NOT NULL THEN
UTL_SMTP.write_data(l_mail_conn, 'BCC: ' || REPLACE(p_bcc, ',', ';') || UTL_TCP.crlf);
END IF;
UTL_SMTP.write_data(l_mail_conn, 'From: ' || p_from || UTL_TCP.crlf);
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || p_subject || UTL_TCP.crlf);
UTL_SMTP.write_data(l_mail_conn, 'Reply-To: ' || p_from || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_data(l_mail_conn, p_message || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
I am now hitting this error - Unrecognized authentication type . I am using Oracle 12c DB. Is there a better way of sending mails than UTL_SMTP ??