Oracle Plsql sending e-mail code via SMTP

Source: Internet
Author: User
Tags mail code

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.