الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

كيف ترسل ايميل عن طريق قاعدة البيانات

Featured Replies

بتاريخ:

كيف ترسل ايميل عن طريق قاعدة البيانات

البروسيجر التالي هو عبارة عن بروسيجر يقوم بارسال ايميل باستخدام SMTP سيرفر يعني اذا لم يكن لديك SMTP فانك تحتاج لتحميلة مع ملاحظة يجب ان يكون المنفذ 25 بين قاعدة البيانات و SMTP server مفتوح اذا كان منفصلين يعني كل واحد علي سيرفر.

ملاحظات لازم تستبل قيمة المتغير mailhost باسم الهوست (سيرفر SMTP)

CREATE OR REPLACE PROCEDURE mailout
 (sender      IN VARCHAR2,
 recipient   IN VARCHAR2,
 ccrecipient IN VARCHAR2,
 subject     IN VARCHAR2,
 message     IN VARCHAR2
 ) IS
 crlf VARCHAR2(2):= UTL_TCP.CRLF;
 connection utl_smtp.connection;
 mailhost VARCHAR2(30) := 'SMTP server';
 header VARCHAR2(1000);
BEGIN --
 -- Start the connection.
 --
 connection := utl_smtp.open_connection(mailhost,25);
 header:= 'Date: '||TO_CHAR(SYSDATE,'dd Mon yy hh24:mi:ss')||crlf||
    'From: '||sender||''||crlf||
 'Subject: '||subject||crlf||
      'To: '||recipient||crlf||
      'CC: '||ccrecipient;
 --
 -- Handshake with the SMTP server
 --
 utl_smtp.helo(connection, mailhost);
 utl_smtp.mail(connection, sender);
 utl_smtp.rcpt(connection, recipient);
 utl_smtp.rcpt(connection, ccrecipient);
 utl_smtp.open_data(connection);
 --
 -- Write the header
 --
 utl_smtp.write_data(connection, header);
 --
 -- The crlf is required to distinguish that what comes next is not simply part of the header..
 --
 utl_smtp.write_data(connection, crlf ||message);
 utl_smtp.close_data(connection);
 utl_smtp.quit(connection);
EXCEPTION
 WHEN UTL_SMTP.INVALID_OPERATION THEN
   dbms_output.put_line(' Invalid Operation in SMTP transaction.');
 WHEN UTL_SMTP.TRANSIENT_ERROR THEN
   dbms_output.put_line(' Temporary problems with sending email - try again later.');
 WHEN UTL_SMTP.PERMANENT_ERROR THEN
   dbms_output.put_line(' Errors in code for SMTP transaction.');	
END;




لاختبار البروسيجر

SQL>execute mailout('"TEST EMAIL" ','[email protected]','[email protected] ','The Subject line' , 'Your text here');

PL/SQL procedure successfully completed





والى يبي يتعمق اكثر بالبكج UTL_SMTP يقراء اكثر عنة لانة عن طريقة تقدر ترسل ايميل علي هيئة SMTP او تقدر ترفق ملف

طبعا تقدر تستفيد منه في الاعمال اليومية مثلا Daily,weekly, monthly jobs , backup …etc

تم تعديل بواسطة KSA_Admin

بتاريخ:

مرحبا
انا بستخدم هاي الطريقة على شان اعرف بس يصير مشكلة في البرنامج - لانه بيبعثلي ايميل بالمشكلة.

  • بعد 7 شهور...
بتاريخ:

[يمين][يمين][يسار]لكن مع تجربة الكود يصعب ارسال بريد باللغة العربية كذلك الكود التالي لا يرسل بالعربي



procedure mail_files ( from_name varchar2,
to_name varchar2,
subject varchar2,
message varchar2,
max_size number default 9999999999,
filename1 varchar2 default null,
filename2 varchar2 default null,
filename3 varchar2 default null,
debug number default 0 ) is
v_smtp_server varchar2(100);


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;

type varchar2_table is table of varchar2(200) index by binary_integer;

file_array varchar2_table;
i binary_integer;

v_file_handle utl_file.file_type;
v_slash_pos number;

mesg_len number;

mesg_too_long exception;
invalid_path exception;

mesg_length_exceeded boolean := false;

begin
select REGION_SMTP_IP into v_smtp_server from L_REGION where REGION_CODE=2;

-- first load the three filenames into an array for easier handling later ...

file_array(1) := filename1;
file_array(2) := filename2;
file_array(3) := filename3;

-- Open the SMTP connection ...
-- ------------------------

conn:= utl_smtp.open_connection( v_smtp_server, v_smtp_server_port );

-- Initial handshaking ...
-- -------------------

utl_smtp.helo( conn, v_smtp_server );
utl_smtp.mail( conn, from_name );
utl_smtp.rcpt( conn, to_name );

utl_smtp.open_data ( conn );


-- build the start of the mail message ...
-- -----------------------------------
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 ||
'This is a Mime message, which your current mail reader may not' || crlf ||
'understand. Parts of the message will appear as text. If the remainder' || crlf ||
'appears as random characters in the message body, instead of as' || crlf ||
'attachments, then you''ll have to extract these parts and decode them' || crlf ||
'manually.' || crlf ||
'' || crlf ||
'--DMW.Boundary.605592468' || crlf ||
'Content-Type:text/plain;name="message.txt";charset=iso-8859-1'|| crlf ||
'font-family="Arabic transparent"' || crlf ||
'Content-Disposition: inline; filename="message.txt"' || crlf ||
'Content-Transfer-Encoding: 7bit' || crlf ||
'' || crlf ||
message || crlf ;

--"Content-Type: text/plain; charset=ISO-8859-1\r\n";
--Content-Type: text/plain;

dbms_output.put_line('2');


mesg_len := length(mesg);

if mesg_len > max_size then
mesg_length_exceeded := true;
end if;

utl_smtp.write_data ( conn, mesg );

-- Append the files ...
-- ----------------




for i in 1..3 loop

-- Exit if message length already exceeded ...

exit when mesg_length_exceeded;

-- If the filename has been supplied ...

if file_array(i) is not null then

begin

-- locate the final '/' or '\' in the pathname ...

v_slash_pos := instr(file_array(i), '/', -1 );

if v_slash_pos = 0 then
v_slash_pos := instr(file_array(i), '\', -1 );
end if;

-- separate the filename from the directory name ...
v_directory_name := substr(file_array(i), 1, v_slash_pos - 1 );
v_file_name := substr(file_array(i), v_slash_pos + 1 );

-- open the file ...

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:text/plain; name="' || v_file_name || '"' ||'charset=iso-8859-1'|| crlf ||
'font-family="Arabic transparent"' || crlf ||
'Content-Disposition: attachment; filename="' || v_file_name || '"' ||'charset=iso-8859-1'|| crlf ||
'Content-Transfer-Encoding: 7bit' || crlf || crlf ;

mesg_len := mesg_len + length(mesg);

utl_smtp.write_data ( conn, mesg );

-- and append the file contents to the end of the message ...


loop

utl_file.get_line(v_file_handle, v_line);

if mesg_len + length(v_line) > max_size then

mesg := '*** truncated ***' || crlf;

utl_smtp.write_data ( conn, mesg );

mesg_length_exceeded := true;

raise mesg_too_long;

end if;

mesg := v_line || crlf;

utl_smtp.write_data ( conn, mesg );

mesg_len := mesg_len + length(mesg);

end loop;

exception
when utl_file.invalid_path then
if debug > 0 then
dbms_output.put_line('Error in opening attachment '||
file_array(i) );
end if;

-- All other exceptions are ignored ....

when others then
null;

end;

dbms_output.put_line('4');


mesg := crlf;

utl_smtp.write_data ( conn, mesg );

-- close the file ...

utl_file.fclose(v_file_handle);

end if;

end loop;

-- append the final boundary line ...

mesg := crlf || '--DMW.Boundary.605592468--' || crlf;

utl_smtp.write_data ( conn, mesg );

-- and close the SMTP connection ...

utl_smtp.close_data( conn );

utl_smtp.quit( conn );




end;
-----------------------------------

[/يمين][/يمين]

[/يسار]

  • بعد 11 شهور...
بتاريخ:

شكرا لك على الطرح المثري ,,,

و بالفعل يتم الأحتياج لمثل الأجراء



و جاري تطبيقه ...


تحيتي

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

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

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

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

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

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.