Log in to smtpserver send mail, support HTML
CREATE OR REPLACE PROCEDURE send_mail ( p_recipient VARCHAR2,--mail recipient P_subject VARCHAR2,--mail header p_message VARCHAR2 --message body ) IS --The following four variables should be assigned according to the actual mail server V_mailhost VARCHAR2 (+): = ' smtp.163.com '; --smtpserver address V_user VARCHAR2 (+): = ' [email protected] '; --Login SmtpServer username v_pass VARCHAR2: = ' System123 '; --Log in to SmtpServer's password v_sender VARCHAR2 (): = ' [email protected] '; --The sender's mailbox. General and Ps_user corresponding V_conn utl_smtp. Connection; --Connection to mail server V_MSG VARCHAR2 (4000); --Mail content BEGIN V_conn: = Utl_smtp.open_connection (V_mailhost, +); UTL _smtp.ehlo (V_conn, v_mailhost); --Is using EHLO () instead of helo () function --otherwise it will be reported: ORA-29279:SMTP PermanentError: 503 5.5.2 Send Hello first. utl_smtp.command (v_conn, ' AUTH LOGIN '); --SmtpServer login check Utl_smtp.command (V_CONN,UTL_RAW.CAST_TO_VARCHAR2 (utl_encode.base64_ Encode (Utl_raw.cast_to_raw (v_user))); Utl_smtp.command (V_CONN,UTL_RAW.CAST_TO_VARCHAR2 (UTL_ Encode.base64_encode (Utl_raw.cast_to_raw (V_pass))); Utl_smtp.mail (V_conn, V_sender); --set sender UTL_SMTP.RCPT (V_conn, p_recipient); --set recipients --Create a message to send note the header message and the message body are blank line v_msg: = ' Date: ' | | To_char (sysdate, ' dd Mon yy hh24:mi:ss ') | | Utl_tcp. CRLF | | ' From: ' | | ' < ' | | V_sender | | ' > ' | | Utl_tcp. CRLF | | ' To: ' | | ' < ' | | p_recipient | | ' > ' | | Utl_tcp. CRLF | | ' Subject: ' | | p_subject | | Utl_tcp. CRLF | | ' Content-type:text/html;charset=GBK ' | | Utl_tcp. CRLF | | Utl_tcp. CRLF --This front is header information | | P_message; --This is the message body Utl_smtp.open_data (v_conn); --Open stream Utl_smtp.write_raw_data (V_conn, Utl_raw.cast_to_raw (CONVERT (v_msg, ' ZHS16GBK ')); -This title and content can be written in Chinese utl_smtp.close_data (v_conn); --Close flow utl_smtp.quit (v_conn); --Close connection EXCEPTION when OTHERS then Dbms_output.put_line (dbms_ Utility.format_error_stack); Dbms_output.put_line (Dbms_utility.format_call_stack) ; end Send_mail;
Oracle Plsql sending e-mail code via SMTP