الانتقال إلى المحتوى

مقال مفصل عن كيفية Sending E-mails from Oracle


عبدالله ندا

Recommended Posts

هلا اخواني اثناء بحثي علي الشبكه وجدت مقال اعتقد انه ممتاز
يقوم بشرح تفصيلي عن كيفية ارسال رسائل الكترونيه من قواعد بيانات اوراكل Sending E-mails from Oracle Database
مع امثله
اترككم الان مع الموقع
http://www.databasejournal.com/features/or...cle.php/1496631

مع تمنياتي بالتوفيق الدائم

رابط هذا التعليق
شارك

This script generates a procedure that will send e-mail from oracle



CREATE OR REPLACE PROCEDURE SEND_MAIL_TCP
( msg_from varchar2 := '[email protected]',
  msg_to varchar2, 
  msg_subject varchar2 := 'E-Mail message from your database', 
msg_text varchar2 := '' ) 
IS 
c utl_tcp.connection; 
rc integer; 
BEGIN c := utl_tcp.open_connection('<<IP>>', 25); -- open the SMTP port 25 on local machine 
rc := utl_tcp.write_line(c, 'HELO localhost'); 
rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from); 
rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to); 
rc := utl_tcp.write_line(c, 'DATA'); 		-- Start message body 
rc := utl_tcp.write_line(c, 'Subject: '||msg_subject); 
rc := utl_tcp.write_line(c, ''); 
rc := utl_tcp.write_line(c, msg_text); 
rc := utl_tcp.write_line(c, '.'); 		-- End of message body 
rc := utl_tcp.write_line(c, 'QUIT'); 
utl_tcp.close_connection©; 			-- Close the connection 
EXCEPTION 
when others then 
raise_application_error(-20000,'Unable to send e-mail message from pl/sql'); END; 

exec send_mail_Tcp(msg_to   =>	'[email protected]',
                  msg_text =>	'Look Ya BEDO, I can send mail from plsql');

رابط هذا التعليق
شارك

Sample code to send an e-mail with attachments using utl_smtp


you can use utl_smtp (http://technet.oracle.com/sample_code/tech/pl_sql/htdocs/maildemo8i_sql.txt) but this method (in 9i this is native) is not very powerful due to an high string parsing and byte manipulation in PL/SQL



create or replace procedure mail_files ( from_name varchar2, 
to_name varchar2, 
subject varchar2, 
message varchar2, 
max_size number default 9999999999, 
filename1 varchar2 default null) 
is 
v_smtp_server varchar2(100) := 'gmapacsmtp.oraclecorp.com'; 
v_smtp_server_port number := 25; 
v_directory_name varchar2(100); 
v_file_name varchar2(100); 
v_line varchar2(1000); 
crlf varchar2(2):= chr(13) || chr(10); 
mesg varchar2(32767); 
conn UTL_SMTP.CONNECTION; 
v_slash_pos number; 
v_file_handle utl_file.file_type; 
invalid_path exception; 
mesg_length_exceeded boolean := false; 
begin conn:= utl_smtp.open_connection( v_smtp_server, v_smtp_server_port ); 
utl_smtp.helo( conn, v_smtp_server ); 
utl_smtp.mail( conn, from_name ); 
utl_smtp.rcpt( conn, to_name ); 
utl_smtp.open_data ( conn ); 
mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf || 
'From: ' || from_name || crlf || 
'Subject: ' || subject || crlf || 
'To: ' || to_name || crlf || 
'Mime-Version: 1.0' || crlf || 
'Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"' || 
crlf || 
'' || crlf || 
'--DMW.Boundary.605592468' || crlf || 
'Content-Type: text/plain; name="message.txt"; charset=US-ASCII' || 
crlf || 
'Content-Disposition: inline; filename="c:\message.txt"' || crlf || 
'Content-Transfer-Encoding: 7bit' || crlf || 
'' || crlf || 
message || crlf ; 
utl_smtp.write_data ( conn, mesg ); 
if filename1 is not null then 
begin v_slash_pos := instr(filename1, '/', -1 ); 
if v_slash_pos = 0 then 
v_slash_pos := instr(filename1, '\', -1 ); 
end if; 
v_directory_name := substr(filename1, 1, v_slash_pos - 1 ); 
v_file_name := substr(filename1, v_slash_pos + 1 ); 
v_file_handle := utl_file.fopen(v_directory_name, v_file_name, 'r' 
); 
-- generate the MIME boundary line ... 
mesg := crlf || '--DMW.Boundary.605592468' || crlf || 
'Content-Type: application/octet-stream; name="' || v_file_name || 

'"' || crlf || 
'Content-Disposition: attachment; filename="' || v_file_name || 
'"' || crlf || 
'Content-Transfer-Encoding: 7bit' || crlf || crlf ; 
utl_smtp.write_data ( conn, mesg ); 
loop 
utl_file.get_line(v_file_handle, v_line); 
mesg := v_line || crlf; 
utl_smtp.write_data ( conn, mesg ); 
end loop; 
exception 
when utl_file.invalid_path then 
dbms_output.put_line('Error in opening attachment '||filename1 
); 
when others then 
null; 
end; 
end if; 
mesg := crlf || '--DMW.Boundary.605592468--' || crlf; 
utl_smtp.close_data( conn ); 
utl_smtp.quit( conn ); 
end;

رابط هذا التعليق
شارك

HTML File Attachement

The below is an example from http://www.samoratech.com/. In this case the message has to be put it in html format


----- Cut it from Here--------------------- 

Declare 


SendorAddress Varchar2(30) := '[email protected]'; 

/* Address of the person who is sending Email */ 



ReceiverAddress varchar2(30) := '[email protected]'; 

/* Address of the person who is receiving Email */ 



EmailServer varchar2(30) := 'mail.Test.com'; 

/* Address of your Email Server Configured for sending emails */ 



Port number := 25; 

/* Port Number responsible for sending email */ 



conn UTL_SMTP.CONNECTION; 

/* UTL_SMTP package establish a connection with the SMTP server */ 



crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 ); 

/* crlf used for carriage return */ 



mesg VARCHAR2( 4000 ); 

/* Variable for storing message contents */ 



mesg_body varchar2(4000) 

/* Variable for storing HTML code */ 

:= ' <html> 

<head> 

<title>Oracle Techniques </title> 

</head> 

<body bgcolor="#FFFFFF" link="#000080"> 

<table cellspacing="0" cellpadding="0" width="100%"> 

<tr align="LEFT" valign="BASELINE"> 

<td width="100%" valign="middle"><h1><font color="#00008B"><b>Send Mail in HTML Format</b></font></h1> 

</td> 

</table> 

<ul> 

<li><b><a href="abc">Oracle Techniques is for DBAs </li> 

<l><b> by aaa </b> </l> 

</ul> 

</body> 

</html>'; 



BEGIN /* Open Connection */ 

conn:= utl_smtp.open_connection( EmailServer, Port ); 

/* Hand Shake */ 

utl_smtp.helo( conn, EmailServer ); 

/* Configure Sender and Recipient with UTL_SMTP */ 

utl_smtp.mail( conn, SendorAddress); 

utl_smtp.rcpt( conn, ReceiverAddress ); 

/* Making Message buffer */ 

mesg:= 

'Date: '||TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' )|| crlf || 

'From:'||SendorAddress|| crlf || 

'Subject: Mail Through ORACLE Database' || crlf || 

'To: '||ReceiverAddress || crlf || 

'' || crlf ||mesg_body||''; 


/* Configure Sending Message */ 

/*You need to put 'MIME-Verion: 1.0' (this is case-sensitive!) */ 

/*Content-Type-Encoding is actually Content-Transfer-Encoding. */ 

/*The MIME-Version, Content-Type, Content-Transfer-Encoding should */ 

/* be the first 3 data items in your message */ 

utl_smtp.data(conn, 'MIME-Version: 1.0' ||CHR(13)|| CHR(10)||'Content-type: text/html' || CHR(13)||CHR(10)||mesg); 

/* Closing Connection */ 

utl_smtp.quit( conn ); 

/* End of logic */ 
END; 

/

رابط هذا التعليق
شارك

هذا الموضوع جاء في وقته ... ان اريد ان ابعت Email عن طريق Oracle ولكن عن طريق Developer و ليس Database و انا استخدم Mailto ولكن استفساري هو كيف تبعث مباشرة اليا للمستقبل بدون ان تفتح outlook وانا اضغط Send

رابط هذا التعليق
شارك

  • بعد 6 شهور...

السلام عليكم

ممكن لو سمحتو تطورو الموضوع، أو تفتحو مشاركة جديدة
لصبح أو يشمل Sending SMS from Oracle
مع تحميل DLL الخاصة بإرسال SMS من Forms6i
لأني بحثت عن الموضوع ووجدتها تباع على النت

وجزاكم الله خيرا
أبو عمر

رابط هذا التعليق
شارك

. . . أو تفتحو مشاركة جديدة

بعد إذنك أبو عمر ,, أفضل أن لا يتم فتح مشاركة منفصلة عن نفس الموضوع ، عشان تكون المعلومات متركزة في مكان واحد قدر الإمكان ..
خاصة إن في أعضاء (مثلي) ليست لديهم أدنى فكرة عن الموضوع ,, وبالتالي نستطيع المتابعة بطريقة متسلسة ..

. . .لأني بحثت عن الموضوع. . .
يلا يا عم ورينا همتك ،، أعتقد إن لديك فكرة مش بطالة عن الموضوع
رابط هذا التعليق
شارك

السلام عليكم

تجدون هنا SMS.OCX
مع setup للمكتبة الخاصة فيه، ولا أعلم إذا كان نسخة تجريبية أم لا

يا ريت لو أحد الإخوان المختصين ب OCX يجربه
ويحمل لنا test form إذا وصل إلى نتيجة

الملف مقسوم على جزئين
الجزء الأول

SMS.part1.exe

رابط هذا التعليق
شارك

لا تنسونا من الدعاء
لا تنسوا الإخوان في فلسطين من الدعاء
لا تنسوا الإخوان في العراق من الدعاء
لا تنسوا المسلمبن في كل مكان من الدعاء

الجزء الثاني:

SMS.part2.rar

تم تعديل بواسطة Naji_Ali
رابط هذا التعليق
شارك

اليكم هذا البرنامج قد يساعد في تطوير هذه الفكرة :
MailStorm Handles all the email communication you ever need to send and receive emails directly from within your Oracle Database! Whether you need to send a single email every now and then or have a mailing list with gazillions of customer, want to create your own incident tracking application or looking for a way to run your own YahooGroups style Forum - MailStorm will enable you to do it!

عنوان الموقع هو :
http://www.orcl-toolbox.com

ايضا يحتوي الموقع على بعض الأدوات المفيدة.

رابط هذا التعليق
شارك

  • بعد 6 سنة...

السلام عليكم

شباب لو سمحتو عايز اعرف ازاي اعمل alter بحيث اسطيع ارسال ايميل الى ال Hotmail انا استخدمت التالي :

alter system set smtp_out_server = '127.0.0.1:25' scope=both;

وعايزاحصل على smtp_out_server لل Hotmail
وشكرا

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية