Home » Developer & Programmer » Forms » Email Code..But!!!!!
Email Code..But!!!!! [message #243844] Sat, 09 June 2007 23:54 Go to next message
Dream
Messages: 11
Registered: June 2007
Location: UAE
Junior Member
hi there,
first of all, thanks for this great fourm and its members for the great offers ..its really help us and provide us with needed information in our field...

may god bless you all:)


======================

i am now working on creating email form from oracle 6i and its working fine...but the problem is [ATTACHMENT] when i send the email..the attchment is not working!!!!

for example, in my form i have [ TO,CC,Attachment,Subject,Body] the attachment will be report which will be automatically attached from another form... and other fields show be enter by users

the problem now is..the attachment NOT sending:(

here is the code

Declare
	---procedure send email
	objOutlook ole2.obj_type;
	objMail ole2.obj_type;
	objARG ole2.list_type;
	attachment ole2.obj_type;
	args ole2.list_type;
	
begin
	objOutlook := ole2.create_obj('outlook.application');
	objarg :=ole2.create_argList;
	ole2.add_arg(objarg,0);

	objmail := ole2.invoke_obj(objOutlook,'CreateItem',objarg);
	ole2.destroy_arglist(objarg);
	
	ole2.set_property(objmail,'To',:TO);
	ole2.set_property(objmail,'CC',:CC);
	ole2.set_property(objmail,'Attach',:Attach);
	ole2.set_property(objmail,'Subject',:SUBJECT);
	ole2.set_property(objmail,'Body',:BODY);
	args:=ole2.create_arglist;
	
	
--	ole2.add_arg(args,attachment);
	OLE2.ADD_ARG(args,'S:\Dream\System\rpts\Contract.rpt23.pdf');
	ole2.invoke(Attachment,'readfromfile',args);
	ole2.destroy_arglist(args);
	
--	OLE2.INVOKE(attachment, 'Add', objarg); i add it 
	ole2.invoke(objmail,'Send');
	
	ole2.invoke(objmail,'Display');
	
	ole2.release_obj(objmail);
	ole2.release_obj(objOutlook);
	ole2.release_obj(attachment); 
	
	Message('your mail sent successsfully');
	Message('your mail sent successsfully');
	clear_form;
	call_form('S:\Dream\system\module5.fmx');
	
	
	exception
	
	when others then
		message(SQLerrm);message(SQLerrm);
	
		
	end;


your highly co-operation will be apperciated

Dream:)

[Updated on: Sun, 10 June 2007 02:42]

Report message to a moderator

Re: Email Code..But!!!!! [message #243975 is a reply to message #243844] Mon, 11 June 2007 02:39 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
Here is the code that i use... hope it helps its on the same lines.

i could not clear your code so i am giving you mine.

Declare
   Outlook_Object OLE2.OBJ_TYPE;
   Mail_Object OLE2.OBJ_TYPE;
   Item1 OLE2.OBJ_TYPE;
   Item2 OLE2.OBJ_TYPE;

   OLEPARAM ole2.list_type;

   var_Send OLE2.OBJ_TYPE;

   var_Attach1 OLE2.OBJ_TYPE;
   var_Attach2 OLE2.OBJ_TYPE;

BEGIN
   Outlook_Object := OLE2.CREATE_OBJ('Outlook.Application'); 
         
   OLEPARAM := OLE2.CREATE_ARGLIST;
   OLE2.ADD_ARG(OLEPARAM,'MAPI');
         
   Mail_Object := OLE2.INVOKE_OBJ(Outlook_Object,'GetNameSpace',OLEPARAM);
   OLE2.DESTROY_ARGLIST( OLEPARAM );
         
   --newMail
   OLEPARAM := OLE2.CREATE_ARGLIST;
   OLE2.ADD_ARG(OLEPARAM,0);
   Item1 := OLE2.INVOKE_OBJ(Outlook_Object,'CreateItem',OLEPARAM);
   OLE2.DESTROY_ARGLIST( OLEPARAM );
         
   -- If you want to display outlook new message screen
   Item2 := OLE2.INVOKE_OBJ(Item1,'Display');
 
   ole2.set_property(Item1,'To', ' ');
   ole2.set_property(Item1,'Subject', :form_fld_subject); 
         -- form_fld_subject is a form field.
   ole2.set_property(Item1,'Body', :form_fld_body);
         -- form_fld_body is a form field.

   -- I am making the user select a file from the mail form. 
   -- The path and filename is stored in :form_fld_filename.

   var_Attach1 := OLE2.GET_OBJ_PROPERTY(Item1,'Attachments');
   OLEPARAM := OLE2.CREATE_ARGLIST;
   OLE2.ADD_ARG(OLEPARAM, :form_fld_filename);
   var_Attach2 := OLE2.INVOKE_OBJ(var_Attach1,'add',OLEPARAM);
   OLE2.DESTROY_ARGLIST( OLEPARAM );


   var_Send := OLE2.INVOKE_OBJ(Item1,'Send');

   OLE2.RELEASE_OBJ( Item1);
   OLE2.RELEASE_OBJ( Mail_Object );
   OLE2.RELEASE_OBJ( Outlook_Object );

   Message('Mail sent seccessfully.........');
   Message('Mail sent seccessfully.........');
END; 


I am using this code in my application for the last 2 years and it works.
ps. this is for 6/6i forms.

Hope it helps,
Hema
Re: Email Code..But!!!!! [message #244193 is a reply to message #243975] Mon, 11 June 2007 22:37 Go to previous messageGo to next message
Dream
Messages: 11
Registered: June 2007
Location: UAE
Junior Member
first of all thanks alot 4 ur great help..i am sure it will help me

i will be thankful if u put screen shot of ur application so the idea be more clear!!!!

Dream:)
Re: Email Code..But!!!!! [message #244233 is a reply to message #243844] Tue, 12 June 2007 01:55 Go to previous messageGo to next message
Dream
Messages: 11
Registered: June 2007
Location: UAE
Junior Member
i will make the idea clear...

i have 2 forms

form number 1 : it has lots of records and next 2 each records there is a buttun...when user click on it...then it will take the information of that recorde as PDF file and it will open Form number 2

then in the form 2 there are [ To, CC,Attach, which the pdf will be in autmatically when user click on the button in form number1, subject, body]

in form 1 i put this code when button pressed

begin
	v_pl_id := get_parameter_list(v_pl_name);
		if not id_null(v_pl_id)then
			destroy_parameter_list(v_pl_name);
		end if;
		v_pl_id := create_parameter_list(v_pl_name);
		add_parameter(v_pl_id,'PARAMFORM',TEXT_PARAMETER,'NO');
		lFileName := 'S:\Tara\Contract-System\rpts\contract.rpt'||:block76.contract_num||'.pdf';
		
		add_parameter(v_pl_id, 'DESNAME',TEXT_PARAMETER,lFileName);
		add_parameter(v_pl_id, 'DESTYPE',TEXT_PARAMETER,'File');
		Add_parameter(v_pl_id,' P_con',TEXT_PARAMETER,(:block76.contract_num));
		v_rep_txt := run_report_object('snd_contract',v_pl_id);
	
		:Global.attachment_name := 'S:\Tara\Contract-System\rpts\Contract.rpt'||:block76.contract_num||'.pdf';
		call_form('S:\Tara\Contract-system\outlook.fmx');
		
end;


in form number 2 i have this code,,in when new form instance

:block13.attach := :Global.attachment_name; 



and in the send button i have this code

Declare
	---procedure send email
	objOutlook ole2.obj_type;
	objMail ole2.obj_type;
	objARG ole2.list_type;
	attachment ole2.obj_type;
	args ole2.list_type;
	
begin
	objOutlook := ole2.create_obj('outlook.application');
	objarg :=ole2.create_argList;
	ole2.add_arg(objarg,0);
	objmail := ole2.invoke_obj(objOutlook,'CreateItem',objarg);
	ole2.destroy_arglist(objarg);
	
	ole2.set_property(objmail,'To',:TO);
	ole2.set_property(objmail,'CC',:CC);
	ole2.set_property(objmail,'Attach',:Attach);
	ole2.set_property(objmail,'Subject',:SUBJECT);
	ole2.set_property(objmail,'Body',:BODY);
	args:=ole2.create_arglist;
	
	ole2.add_arg(args,attachment);

	ole2.invoke(Attachment,'readfromfile',args);
	ole2.destroy_arglist(args);
	 
	ole2.invoke(objmail,'Send');
	
	ole2.invoke(objmail,'Display');
	
	ole2.release_obj(objmail);
	ole2.release_obj(objOutlook);
	ole2.release_obj(attachment); 
	
	Message('your mail sent successsfully');
	Message('your mail sent successsfully');
	clear_form;
	call_form('S:\Tara\Contract-system\module5.fmx');
	
	exception
	
	when others then
		message(SQLerrm);message(SQLerrm);
		
	end;



i wish if anyone provide me with help:)

thanks in advance to all:)

Dream
Re: Email Code..But!!!!! [message #245918 is a reply to message #243844] Tue, 19 June 2007 05:05 Go to previous messageGo to next message
emadbsb
Messages: 334
Registered: May 2005
Location: egypt
Senior Member

those codes for sending email is so useful

but i have a question if i can send an email independent from any program for send mail like "outlook"


is there a way to do that
Re: Email Code..But!!!!! [message #246453 is a reply to message #245918] Thu, 21 June 2007 00:54 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
The below code will create a mail into the "Outbox" of your outlook application. This will be sent from the "default" user of outlook as you have set.

Hemavb
Re: Email Code..But!!!!! [message #246480 is a reply to message #243844] Thu, 21 June 2007 01:27 Go to previous messageGo to next message
emadbsb
Messages: 334
Registered: May 2005
Location: egypt
Senior Member

I don't want to send email using the oulook
i want to send emails independent from any program
because not all the clients have a program to send mail

is there any solution to this program
Re: Email Code..But!!!!! [message #246488 is a reply to message #246480] Thu, 21 June 2007 01:42 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
Do you have a mail server in your office? If you want to send directly there is one more way, but for that you need a mail server like exchange or vpop3 or something like that. The code will send the mail directly from the SMTP without using outlook.

If yes, use the UTL_SMTP package from the SYS user of the database. It is available in 10g and 9i. You can give execute rights to your db user and call the package in d2k.

There is an example in the body of the package. It should help you.
Re: Email Code..But!!!!! [message #246491 is a reply to message #243844] Thu, 21 June 2007 01:48 Go to previous messageGo to next message
emadbsb
Messages: 334
Registered: May 2005
Location: egypt
Senior Member

yes i am using an exchange email server
and all the users can open there browser on that addresss
http://comsrv/exchange/

comsrv is our email server

and i am using oracle 8i
Re: Email Code..But!!!!! [message #247490 is a reply to message #243844] Tue, 26 June 2007 02:08 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
Dreamz & emadbsb

  *   DECLARE
  *     c utl_smtp.connection;
  *
  *     PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
  *     BEGIN
  *       utl_smtp.write_data(c, name || ': ' || header || utl_tcp.CRLF);
  *     END;
  *
  *   BEGIN
  *     c := utl_smtp.open_connection('smtp-server.acme.com');
  *     utl_smtp.helo(c, 'foo.com');
  *     utl_smtp.mail(c, 'sender@foo.com');
  *     utl_smtp.rcpt(c, 'recipient@foo.com');
  *     utl_smtp.open_data(c);
  *     send_header('From',    '"Sender" <sender@foo.com>');
  *     send_header('To',      '"Recipient" <recipient@foo.com>');
  *     send_header('Subject', 'Hello');
  *     utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!');
  *     utl_smtp.close_data(c);
  *     utl_smtp.quit(c);
  *   EXCEPTION
  *     WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
  *       BEGIN
  *         utl_smtp.quit(c);
  *       EXCEPTION
  *         WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
  *           NULL; -- When the SMTP server is down or unavailable, we don't
  *                 -- have a connection to the server. The quit call will
  *                 -- raise an exception that we can ignore.
  *       END;
  *       raise_application_error(-20000,
  *         'Failed to send mail due to the following error: ' || sqlerrm);
  *   END;


This will send the mail directly. Without Outlook. You need to have a SMTP port on your mail server. From here the mail will be sent.

The user you use should have execute grant on UTL_SMTP package of SYS user.
Re: Email Code..But!!!!! [message #247563 is a reply to message #243844] Tue, 26 June 2007 06:51 Go to previous messageGo to next message
emadbsb
Messages: 334
Registered: May 2005
Location: egypt
Senior Member

there is compilation errors while compiling this procedure

on "utl_tcp.CRLF" it gives me error of cannot direclty access
remote package variable or cursor

where is the problem
Re: Email Code..But!!!!! [message #247585 is a reply to message #243844] Tue, 26 June 2007 07:45 Go to previous messageGo to next message
hemavb
Messages: 103
Registered: May 2007
Location: Dubai , UAE
Senior Member
Two ways to solve this...

1)
Use CHR(10) instead of utl_tcp.CRLF

or

2)
The user you use should have execute grant on UTL_TCP package of SYS user
Re: Email Code..But!!!!! [message #400290 is a reply to message #243844] Mon, 27 April 2009 07:48 Go to previous messageGo to next message
skamransajjad
Messages: 42
Registered: December 2008
Location: Pakistan
Member

when I apply above code, I receive the below warning

A program is trying to send mail using Item.Send

How can I bypass this message ?

Regards,

Kamran
Re: Email Code..But!!!!! [message #401634 is a reply to message #400290] Tue, 05 May 2009 20:52 Go to previous message
djmartin
Messages: 10180
Registered: March 2005
Location: Canberra ACT Australia
Senior Member
Account Moderator
Have you solved your problem?

What is issuing this message?

David
Previous Topic: Sequences Numbers
Next Topic: Message acknowledgment
Goto Forum:
  


Current Time: Thu Dec 08 18:26:06 CST 2016

Total time taken to generate the page: 0.17585 seconds