CREATE OR REPLACE PROCEDURE MAIL_GONDER (p_to        IN VARCHAR2,
                                       p_subject   IN VARCHAR2,
                                       p_message   IN VARCHAR2)
AS
   l_mail_conn   UTL_SMTP.connection;
   p_from        VARCHAR2 (30) := 'Gonderici Bilgisi';
   p_smtp_host   VARCHAR2 (30) := 'mail server bilgisi';
   p_smtp_port   NUMBER := 25;
BEGIN
   l_mail_conn := UTL_SMTP.open_connection (p_smtp_host, p_smtp_port);
   UTL_SMTP.helo (l_mail_conn, p_smtp_host);
   UTL_SMTP.mail (l_mail_conn, p_from);
   UTL_SMTP.rcpt (l_mail_conn, p_to);

   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);
   UTL_SMTP.write_data (l_mail_conn, 'From: ' || 'Database Report Mail' || 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);
END;
/
begin
  dbms_network_acl_admin.create_acl (
    acl         => 'utl_mail.xml',
    description => 'Allow mail to be send',
    principal   => 'Mail Gonderecek Username',
    is_grant    => TRUE,
    privilege   => 'connect'
    );
    commit;
end;


BEGIN
  DBMS_NETWORK_ACL_ADMIN.assign_acl (
  acl => 'utl_mail.xml',
  host => 'mail server', 
  lower_port => '25',
  upper_port => '25');
  COMMIT;
END;
/
Begin
MAIL_GONDER('Gonderilen mail adresi','Konu','Deneme mesajı');
End;
/

exec MAIL_GONDER('Gonderilen mail adresi','Konu','Deneme mesajı');

Loading