Advertisement
Guest User

Untitled

a guest
May 26th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.61 KB | None | 0 0
  1. CREATE OR REPLACE PROCEDURE send_mail_test (
  2.     smtphost         IN VARCHAR2,
  3.     smtpport         IN PLS_INTEGER DEFAULT 25,
  4.     mailfrom         IN VARCHAR2,
  5.     rcptto           IN VARCHAR2,
  6.     messagesubject   IN VARCHAR2,
  7.     messagebody      IN VARCHAR2,
  8.     username         IN VARCHAR2,
  9.     password         IN VARCHAR2
  10. ) IS
  11.     l_conn               UTL_SMTP.connection;
  12.     l_encoded_username   VARCHAR2(2048);
  13.     l_encoded_password   VARCHAR2(2048);
  14.     crlf                 VARCHAR2(2) := CHR(10)
  15.      ||  CHR(13);
  16. BEGIN
  17.     l_encoded_username := UTL_RAW.cast_to_varchar2(
  18.         UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(username) )
  19.     );
  20.     l_encoded_password := UTL_RAW.cast_to_varchar2(
  21.         UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(password) )
  22.     );
  23.     l_conn := UTL_SMTP.open_connection(smtphost,smtpport);
  24.     UTL_SMTP.ehlo(l_conn,smtphost);
  25.  
  26.     UTL_SMTP.command(l_conn,'AUTH','LOGIN');
  27.     UTL_SMTP.command(l_conn,username);
  28.     UTL_SMTP.command(l_conn,password);
  29.     UTL_SMTP.mail(l_conn,mailfrom);
  30.     UTL_SMTP.rcpt(l_conn,rcptto);
  31.     UTL_SMTP.open_data(l_conn);
  32.     UTL_SMTP.write_data(
  33.         l_conn,
  34.         'To: '
  35.          ||  rcptto
  36.          ||  crlf
  37.     );
  38.     UTL_SMTP.write_data(
  39.         l_conn,
  40.         'From: '
  41.          ||  mailfrom
  42.          ||  crlf
  43.     );
  44.     UTL_SMTP.write_data(
  45.         l_conn,
  46.         'Subject: '
  47.          ||  messagesubject
  48.          ||  crlf
  49.     );
  50.     UTL_SMTP.write_data(
  51.         l_conn,
  52.         messagebody
  53.          ||  crlf
  54.          ||  crlf
  55.     );
  56.     UTL_SMTP.close_data(l_conn);
  57.     UTL_SMTP.quit(l_conn);
  58. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement