I'm sending thousands of emails via Oracle 18c to an SMTP server. The emails are different.
I'm using the following code in a loop that I put inside a job. This code works great, however it's quite slow. (I'm talking about the execution time.)
I was wondering if there is any way to speed it up. For example, openning the SMTP connection only once and use it for the entire loop.
Has anyone tried something like that please ?
Thanks. Cheers,
Thanks.
declare
Connexion UTL_SMTP.connection;
l_boundary VARCHAR2(50) := '----=*#abc1234321cba#*=';
-- other variables are declared somewhere else...
Begin
Connexion := UTL_SMTP.open_connection(Host, Port);
UTL_SMTP.AUTH(Connexion,KeyName,KeyValue, 'PLAIN');
UTL_SMTP.helo(Connexion, Host);
UTL_SMTP.mail(Connexion, MailFrom_);
-- Add email
UTL_SMTP.rcpt(Connexion, EmailAddress);
-- Open reader to write data
UTL_SMTP.open_data(Connexion);
-- Date
UTL_SMTP.write_data(Connexion, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || UTL_TCP.crlf);
-- Mail to
UTL_SMTP.write_data(Connexion, 'To: ' || EmailAddress || UTL_TCP.crlf);
-- Subject
UTL_SMTP.write_raw_data(Connexion, utl_raw.cast_to_raw('Subject:' || Subject_));
UTL_SMTP.WRITE_DATA(Connexion, UTL_TCP.CRLF);
-- Message html
UTL_SMTP.write_data(Connexion, '--' || l_boundary || UTL_TCP.crlf);
UTL_SMTP.write_data(Connexion, 'Content-Type: text/html; charset="UTF-8"' || UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_raw_data(Connexion, utl_raw.cast_to_raw(MessageInHTML));
UTL_SMTP.write_data(Connexion, UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_data(Connexion, '--' || l_boundary || '--' || UTL_TCP.crlf);
UTL_SMTP.close_data(Connexion);
UTL_SMTP.quit(Connexion);
end;