Modernisation Oracle Forms

Comment envoyer un courriel avec plusieurs pièces jointes au moyen d'Outlook

OBJECTIF

Comment envoyer un courriel avec plusieurs pièces jointes au moyen d'Outlook.

Mise en garde

L'exemple de programme de cet article est fourni à des fins éducatives seulement

et n'est PAS pris en charge par Oracle Support Services. Il a toutefois été testé

à l'interne et fonctionne comme décrit. Nous ne garantissons pas qu'il

fonctionnera chez vous : testez-le donc dans votre environnement avant de vous

y fier.

PORTÉE ET APPLICATION

Le code ci-dessous envoie un courriel avec plusieurs

pièces jointes au moyen d'Outlook.

---

Declare

  /*declaration of the Outlook Object Variables*/
  application ole2.OBJ_TYPE;      
  hMailItem ole2.OBJ_TYPE;
  hRecipients ole2.OBJ_TYPE;
  recipient ole2.OBJ_TYPE;

  /*declaration of the argument list*/  
  args OLE2.LIST_TYPE;    
          
  msg_attch OLE2.OBJ_TYPE; 
  attachment OLE2.OBJ_TYPE; 

  des VARCHAR2(80) := 'FILE_NAME'; 
  attch VARCHAR2(80) := 'C:\temp\bt.TXT';

  begin
  /*create the Application Instance*/
  application:=ole2.create_obj('Outlook.Application');            
    
  args:=ole2.create_arglist;                                      
  ole2.add_arg(args,0);
  hMailItem:=ole2.invoke_obj(application,'CreateItem',args);
  ole2.destroy_arglist(args);
  
  msg_attch := OLE2.GET_OBJ_PROPERTY(hMailItem,'Attachments'); 

  /* Attach the 1st file */
  args := OLE2.CREATE_ARGLIST; 
  OLE2.ADD_ARG(args,attch); 
  attachment := OLE2.INVOKE_OBJ(msg_attch,'Add',args); 
  ole2.destroy_arglist(args); 
  OLE2.SET_PROPERTY(attachment,'name',des); 
  OLE2.SET_PROPERTY(attachment,'position',1); 
  OLE2.SET_PROPERTY(attachment,'type',1); 
  OLE2.SET_PROPERTY(attachment,'source',Attch); 
  args := OLE2.CREATE_ARGLIST; 
  OLE2.ADD_ARG(args,Attch); 
  OLE2.INVOKE(attachment,'ReadFromFile',args); 
  OLE2.DESTROY_ARGLIST(args); 
  
  /* Attach the 2nd file */
  attch:='c:\temp\test.dst';
  args := OLE2.CREATE_ARGLIST; 
  OLE2.ADD_ARG(args,attch); 
  attachment := OLE2.INVOKE_OBJ(msg_attch,'Add',args); 
  ole2.destroy_arglist(args); 
  OLE2.SET_PROPERTY(attachment,'name',des); 
  OLE2.SET_PROPERTY(attachment,'position',2); 
  OLE2.SET_PROPERTY(attachment,'type',1); 
  OLE2.SET_PROPERTY(attachment,'source',attch); 
  args := OLE2.CREATE_ARGLIST; 
  OLE2.ADD_ARG(args,Attch); 
  OLE2.INVOKE(attachment,'ReadFromFile',args); 
  OLE2.DESTROY_ARGLIST(args); 
  
  /*Get the Recipients property of the MailItem object:  
  Returns a Recipients collection that represents all the Recipients for the Outlook item*/
  args:=ole2.create_arglist;
  hRecipients:=ole2.get_obj_property(hMailItem,'Recipients',args);
  ole2.destroy_arglist(args);
    
  /*Use the Add method to create a recipients Instance and add it to the Recipients collection*/
  args:=ole2.create_arglist; 
  ole2.add_arg(args,'myname@myserver.com');
  recipient:=ole2.invoke_obj(hRecipients,'Add',args);

    /* put the property Type of the recipient Instance  to value needed (0=Originator,1=To,2=CC,3=BCC)*/
  ole2.set_property(recipient,'Type',1);
  ole2.destroy_arglist(args);
    
  /*Resolve the Recipients collection*/
  args:=ole2.create_arglist;
  ole2.invoke(hRecipients,'ResolveAll',args);
   
  /*set the Subject and Body properties*/
  ole2.set_property(hMailItem,'Subject','Test OLE2 to Outlook');
  ole2.set_property(hMailItem,'Body','this is body text');
  
    
  /*Save the mail*/ 
  ole2.invoke(hMailItem,'Save',args);
  ole2.destroy_arglist(args);

  /*Send the mail*/ 
  args:=ole2.create_arglist;
  ole2.invoke(hMailItem,'Send',args);
  ole2.destroy_arglist(args); 
   
  /*Release all your Instances*/
  release_obj(application);
  release_obj(hRecipients);
  release_obj(recipient);
  release_obj(hMailItem);
   
  end; 

DOCUMENTS CONNEXES

Note 119828.1 OLE AUTOMATION: Example Sending a Mail From Forms to Outlook