send email : utl_smtp « System Packages « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » System Packages » utl_smtp 
31. 40. 1. send email
SQL> CREATE OR REPLACE PROCEDURE p_send_email
  2                              (p_mailhost VARCHAR2,
  3                               p_from_address VARCHAR2,
  4                               p_to_address VARCHAR2,
  5                               p_message_text VARCHAR2,
  6                               p_returnCode OUT NUMBER,
  7                               p_err_msg OUT VARCHAR2)
  8  IS
  9    mail_conn utl_smtp.connection;
 10  BEGIN
 11    mail_conn :=utl_smtp.open_connection(p_mailhost,25);
 12    utl_smtp.helo(mail_conn,p_mailhost);
 13    utl_smtp.mail(mail_conn,p_from_address);
 14    utl_smtp.rcpt(mail_conn,p_to_address);
 15    utl_smtp.open_data(mail_conn);
 16    utl_smtp.write_data(mail_conn,p_message_text);
 17    utl_smtp.close_data(mail_conn);
 18    utl_smtp.quit(mail_conn);
 19    p_returnCode :=0;
 20  EXCEPTION
 21    WHEN OTHERS THEN
 22      p_returnCode :=SQLCODE;
 23      p_err_msg :=SQLERRM;
 24  END;
 25  /

SQL>
SQL> -- Sample code to execute p_send_email
SQL> declare
  2    returnCode number;
  3    err_msg varchar2(1000);
  4  begin
  5    p_send_email('mail.c.com',
  6                 'b@c.com',
  7                 'b@c.com',
  8                 'From:'||'B'||CHR(13)||CHR(10)||
  9                 'Subject:'||'Message from B'||CHR(13)||CHR(10)||
 10                 CHR(13)||CHR(10)||
 11                 'This is a test message.',
 12                 returnCode,
 13                 err_msg);
 14    IF (returnCode <>0)THEN
 15      dbms_output.put_line('ERR:'||err_msg);
 16    END IF;
 17  end;
 18  /

SQL>
31. 40. utl_smtp
31. 40. 1. send email
31. 40. 2. Send out email with utl_smtp
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.