Haneef Puttur

Oracle PL/SQL to Send ARABIC Emails with SMTP AUTHENTICATED Server UTL_SMTP

 declare

 TO_EMAIL VARCHAR2(255) := 'toemailaddress';
 FROM_EMAIL VARCHAR2(255) := 'fromemailaddress';
 MAIL_SUBJECT VARCHAR2(255) := 'Test Subject';
 FROM_NAME VARCHAR2(255) := 'FROM NAME';
 EMAIL_MESSAGE VARCHAR2(255) := 'سؤال اليوم : ما هو الحل ';
 
 
 smtp_conn UTL_SMTP.CONNECTION;
 smtp_username VARCHAR2 (200) := 'username';
 smtp_server VARCHAR2 (60) := 'smtpserver address';
 smtp_password VARCHAR2 (200) := 'smtp password';
 
 
begin

 smtp_conn := UTL_SMTP.Open_Connection(smtp_server);
 UTL_SMTP.Helo(smtp_conn, smtp_server);
 UTL_SMTP.command (smtp_conn, 'AUTH LOGIN');
 UTL_SMTP.command (smtp_conn, UTL_RAW.cast_to_varchar2 (UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (smtp_username))));
 UTL_SMTP.command (smtp_conn, UTL_RAW.cast_to_varchar2 (UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (smtp_password))));
 UTL_SMTP.Mail(smtp_conn, FROM_EMAIL);
 UTL_SMTP.Rcpt(smtp_conn, TO_EMAIL);
 UTL_SMTP.OPEN_DATA(smtp_conn);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'Subject: =?UTF-8?Q?' || UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.QUOTED_PRINTABLE_ENCODE(UTL_RAW.CAST_TO_RAW(EMAIL_SUBJECT))) ||'?=' || UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'MIME-version: 1.0' || UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'Content-Type: text/html;charset=utf-8' || UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'Content-Transfer-Encoding: quoted-printable '|| UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'Date: ' || TO_CHAR(SYSDATE, 'dd Mon yy hh24:mi:ss' ) ||' -0800 (GMT)' || UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'From: "'|| FROM_NAME|| '"<'|| FROM_EMAIL|| '>' || UTL_TCP.CRLF);
 UTL_SMTP.WRITE_DATA(smtp_conn, 'To: ' || TO_EMAIL || UTL_TCP.CRLF); 
 UTL_SMTP.WRITE_DATA(smtp_conn, UTL_TCP.CRLF);
 UTL_SMTP.WRITE_RAW_DATA(smtp_conn, UTL_ENCODE.QUOTED_PRINTABLE_ENCODE(UTL_RAW.CAST_TO_RAW(EMAIL_MESSAGE)));
 UTL_SMTP.WRITE_DATA(smtp_conn, UTL_TCP.CRLF);
 UTL_SMTP.CLOSE_DATA(smtp_conn);
 UTL_SMTP.QUIT(smtp_conn);
END;
Exit mobile version