send mail with attached objects

Dart, Jocelyn jocelyn.dart at sap.com
Thu Feb 28 01:45:44 EST 2002


Your code looks reasonable. You might want to delete
in a separate program in case the initial send fails.=20
Jocelyn
 
-----Original Message-----
From: Daniel Fern=E1ndez [mailto:wfdfl1975 at yahoo.es]
Sent: Thursday, 28 February 2002 1:59 AM
To: SAP-WUG at MITVMA.MIT.EDU
Subject: Re: send mail with attached objects
 
 
Hi Jocelyn,
 
Thanks for your answer.
 
I have folowed your instructions and It4s work fine.
I suposse that after send the message to my inbox
folder, I must to delete it in private folder.
 
is there a better way to send this type of message
(with a attached object) ????
 
The final code is this:
 
REPORT Z_MAIL .
 
 
data: S_MESSAGE type SODOCCHGI1,
      S_LIST_OBJ type SOLISTI1 occurs 0,
      S_USER_DATS type SOUDATAI1,
      S_USER type SOUDNAMEI1,
      S_DOCUMENT type SOFOLENTI1,
      S_TASK_DESCR TYPE TLINE OCCURS 0,
      S_TASK_DESCR_C TYPE SOLISTI1 OCCURS 0,
      S_OBJECT type soxobj,
      S_DESCR_ATTACH type SOATTCHGI1 occurs 0 with
header line,
      S_RECEIVERS TYPE SOMLRECI1 OCCURS 0 WITH HEADER
LINE.
 
 
* SAP folders of user that receive the mail.
 
 
S_USER-SAPNAME =3D 'DFERNANDEZ'. "(User)
 
CALL FUNCTION 'SO_USER_READ_API1'
    EXPORTING
         USER                      =3D S_USER
    IMPORTING
         USER_DATA                 =3D S_USER_DATS
    EXCEPTIONS
         USER_NOT_EXIST            =3D 1
         PARAMETER_ERROR           =3D 2
         X_ERROR                   =3D 3
         OTHERS                    =3D 4.
 
 
* Obtain Task description
 
CALL FUNCTION 'SWU_GET_TASK_TEXTLINES'
    EXPORTING
          TASK              =3D 'TS99900015'  "(Your
task)
*        WI_ID             =3D
*         WIHEADER          =3D
          USAGE             =3D 'W'
          LINEWIDTH         =3D 75
          LANGUAGE          =3D SY-LANGU
    TABLES
          ASCII_TEXT_LINES  =3D S_TASK_DESCR
*         CONTAINER         =3D
*         HTML_TEXT_LINES   =3D
    EXCEPTIONS
         WRONG_USAGE       =3D 1
         TEXT_NOT_FOUND    =3D 2
         TEXT_SYSTEM_ERROR =3D 3
         OTHERS            =3D 4.
 
* obtain the subject message
 
S_MESSAGE-OBJ_DESCR =3D 'message Subject'.
 
* We will create the 'text' message with the task
description and the
* subject IN PRIVATE FOLDER
 
S_TASK_DESCR_C[] =3D S_TASK_DESCR[].
 
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
     EXPORTING
          FOLDER_ID                  =3D
S_USER_DATS-INBOXFOL
          DOCUMENT_DATA              =3D S_MESSAGE
          DOCUMENT_TYPE              =3D 'RAW'
    IMPORTING
         DOCUMENT_INFO              =3D S_DOCUMENT
    TABLES
         OBJECT_HEADER              =3D S_TASK_DESCR_C
         OBJECT_CONTENT             =3D S_TASK_DESCR_C
    EXCEPTIONS
         FOLDER_NOT_EXIST           =3D 1
         DOCUMENT_TYPE_NOT_EXIST    =3D 2
         OPERATION_NO_AUTHORIZATION =3D 3
         PARAMETER_ERROR            =3D 4
         X_ERROR                    =3D 5
         ENQUEUE_ERROR              =3D 6
         OTHERS                     =3D 7.
 
 
* object dats
 
S_OBJECT-LOGSYS =3D 'SAPI'. "(your logic system)
S_OBJECT-OBJTYPE =3D 'BKPF'.
S_OBJECT-OBJKEY =3D 'ES0100190000012002'. "(Object key)
S_OBJECT-DESCRIBE =3D 'Description'.
S_OBJECT-METHOD =3D 'DISPLAY'.
 
append S_OBJECT to S_LIST_OBJ.
 
 
* We write de object description
 
S_DESCR_ATTACH-OBJ_DESCR =3D 'Factura'.
 
* Add the object to the mail.
 
CALL FUNCTION 'SO_ATTACHMENT_INSERT_API1'
     EXPORTING
          DOCUMENT_ID                =3D
S_DOCUMENT-DOC_ID
          ATTACHMENT_DATA            =3D S_DESCR_ATTACH
          ATTACHMENT_TYPE            =3D 'OBJ'
*    IMPORTING
*         ATTACHMENT_INFO            =3D
     TABLES
          ATTACHMENT_HEADER          =3D S_LIST_OBJ
          ATTACHMENT_CONTENT         =3D S_LIST_OBJ
*         CONTENTS_HEX               =3D
    EXCEPTIONS
         DOCUMENT_NOT_EXIST         =3D 1
         ATTACHMENT_TYPE_NOT_EXIST  =3D 2
         OPERATION_NO_AUTHORIZATION =3D 3
         PARAMETER_ERROR            =3D 4
         X_ERROR                    =3D 5
         ENQUEUE_ERROR              =3D 6
         OTHERS                     =3D 7.
 
 
* Send the mail to inbox.
 
S_RECEIVERS-RECEIVER =3D 'DFERNANDEZ'.
S_RECEIVERS-REC_TYPE =3D 'B'.
S_RECEIVERS-EXPRESS =3D 'X'.
APPEND S_RECEIVERS.
 
CALL FUNCTION 'SO_OLD_DOCUMENT_SEND_API1'
     EXPORTING
          DOCUMENT_ID                =3D
S_DOCUMENT-DOC_ID
*          PUT_IN_OUTBOX              =3D 'X'
*    IMPORTING
*         SENT_TO_ALL                =3D
     TABLES
          RECEIVERS                  =3D S_RECEIVERS
    EXCEPTIONS
         TOO_MANY_RECEIVER          =3D 1
         DOCUMENT_NOT_SENT          =3D 2
         DOCUMENT_NOT_EXIST         =3D 3
         OPERATION_NO_AUTHORIZATION =3D 4
         PARAMETER_ERROR            =3D 5
         X_ERROR                    =3D 6
         ENQUEUE_ERROR              =3D 7
         OTHERS                     =3D 8.
 
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
* delete the document of the private folder.
 
CALL FUNCTION 'SO_DOCUMENT_DELETE_API1'
     EXPORTING
          DOCUMENT_ID                =3D
S_DOCUMENT-DOC_ID
*         UNREAD_DELETE              =3D
*         PUT_IN_TRASH               =3D 'X'
    EXCEPTIONS
         DOCUMENT_NOT_EXIST         =3D 1
         OPERATION_NO_AUTHORIZATION =3D 2
         PARAMETER_ERROR            =3D 3
         X_ERROR                    =3D 4
         ENQUEUE_ERROR              =3D 5
         OTHERS                     =3D 6.
 
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
 
Best regards,
 
 
Daniel
 
 
 --- "Dart, Jocelyn" <jocelyn.dart at sap.com> escribis:
> Hi Daniel,
> That's correct.  You create the document in the
> private folder
> and then send it on to the inbox (either of the same
> user or another
> user).   It's a two part process.
>
> FM SO_OLD_DOCUMENT_SEND_API1 should suit your
> design.
>
> Regards,
>         Jocelyn Dart
> Consultant (EBP, BBP, Ecommerce, Internet
> Transaction Server, Workflow)
> SAP Australia
> Email jocelyn.dart at sap.com
> <mailto:jocelyn.dart at sap.com>
> Tel: +61 412 390 267
> Fax: +61 2 9935 4880
>
>
> -----Original Message-----
>> From: Daniel Fernandez [mailto:wfdfl1975 at yahoo.es]
> Sent: Tuesday, 26 February 2002 7:45 PM
> To: SAP-WUG at MITVMA.MIT.EDU
> Subject: Re: send mail with attached objects
>
>
> Hi Govind,Raskin, Hi all,
>
> I have investigated the API functions for to send
> mail
> with attached objects (like a invoice or a purchase
> order) and I have a problem.
>
> I I try to add a sap office mail in the private
> folder, all works Ok, but if I try to add it in the
> inbox folder an error of authoritation is showed.
>
> I4m the SAP_ALL and SAP_NEW in development system
>
> The code (it works for de private folder) is:
>
> data: S_MESSAGE type SODOCCHGI1,
>       S_LIST_OBJ type SOLISTI1 occurs 0,
>       S_USER_DATS type SOUDATAI1,
>       S_USER type SOUDNAMEI1,
>       S_DOCUMENT type SOFOLENTI1,
>       S_TASK_DESCR TYPE TLINE OCCURS 0,
>       S_TASK_DESCR_C TYPE SOLISTI1 OCCURS 0,
>       S_OBJECT type soxobj,
>       S_DESCR_ATTACH type SOATTCHGI1 occurs 0 with
> header line.
>
>
> * SAP folders of user that receive the mail.
>
>
> S_USER-SAPNAME =3D 'DFERNANDEZ'. "(User)
>
> CALL FUNCTION 'SO_USER_READ_API1'
>     EXPORTING
>          USER                      =3D S_USER
>     IMPORTING
>          USER_DATA                 =3D S_USER_DATS
>     EXCEPTIONS
>          USER_NOT_EXIST            =3D 1
>          PARAMETER_ERROR           =3D 2
>          X_ERROR                   =3D 3
>          OTHERS                    =3D 4.
>
>
> * Obtain Task description
>
> CALL FUNCTION 'SWU_GET_TASK_TEXTLINES'
>     EXPORTING
>           TASK              =3D 'TS99900015'  "(Your
> task)
> *        WI_ID             =3D
> *         WIHEADER          =3D
>           USAGE             =3D 'W'
>           LINEWIDTH         =3D 75
>           LANGUAGE          =3D SY-LANGU
>     TABLES
>           ASCII_TEXT_LINES  =3D S_TASK_DESCR
> *         CONTAINER         =3D
> *         HTML_TEXT_LINES   =3D
>     EXCEPTIONS
>          WRONG_USAGE       =3D 1
>          TEXT_NOT_FOUND    =3D 2
>          TEXT_SYSTEM_ERROR =3D 3
>          OTHERS            =3D 4.
>
> * obtain the subject message
>
> S_MESSAGE-OBJ_DESCR =3D 'message Subject'.
>
> * We will create the 'text' message with the task
> description and the
> * subject
>
> * If The field S_USER_DATS-INBOXFOL is changed for
> * S_USER_DATS-PRIVATFOL the message is correctly
> sended to the user
>
> S_TASK_DESCR_C[] =3D S_TASK_DESCR[].
>
> CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
>      EXPORTING
>           FOLDER_ID                  =3D
> S_USER_DATS-INBOXFOL
>           DOCUMENT_DATA              =3D S_MESSAGE
>           DOCUMENT_TYPE              =3D 'RAW'
>     IMPORTING
>          DOCUMENT_INFO              =3D S_DOCUMENT
>     TABLES
>          OBJECT_HEADER              =3D S_TASK_DESCR_C
>          OBJECT_CONTENT             =3D S_TASK_DESCR_C
>     EXCEPTIONS
>          FOLDER_NOT_EXIST           =3D 1
>          DOCUMENT_TYPE_NOT_EXIST    =3D 2
>          OPERATION_NO_AUTHORIZATION =3D 3
>          PARAMETER_ERROR            =3D 4
>          X_ERROR                    =3D 5
>          ENQUEUE_ERROR              =3D 6
>          OTHERS                     =3D 7.
>
>
> * object dats
>
> S_OBJECT-LOGSYS =3D 'SAPI'. "(your logic system)
> S_OBJECT-OBJTYPE =3D 'BKPF'.
> S_OBJECT-OBJKEY =3D 'ES0100190000012002'. "(Object
> key)
> S_OBJECT-DESCRIBE =3D 'Description'.
> S_OBJECT-METHOD =3D 'DISPLAY'.
>
> append S_OBJECT to S_LIST_OBJ.
>
>
> * We write de object description
>
> S_DESCR_ATTACH-OBJ_DESCR =3D 'Factura'.
>
> * Add the object to the mail.
>
> CALL FUNCTION 'SO_ATTACHMENT_INSERT_API1'
>      EXPORTING
>           DOCUMENT_ID                =3D
> S_DOCUMENT-DOC_ID
>           ATTACHMENT_DATA            =3D
> S_DESCR_ATTACH
>           ATTACHMENT_TYPE            =3D 'OBJ'
> *    IMPORTING
> *         ATTACHMENT_INFO            =3D
>      TABLES
>           ATTACHMENT_HEADER          =3D S_LIST_OBJ
>           ATTACHMENT_CONTENT         =3D S_LIST_OBJ
> *         CONTENTS_HEX               =3D
>     EXCEPTIONS
>          DOCUMENT_NOT_EXIST         =3D 1
>          ATTACHMENT_TYPE_NOT_EXIST  =3D 2
>          OPERATION_NO_AUTHORIZATION =3D 3
>          PARAMETER_ERROR            =3D 4
>          X_ERROR                    =3D 5
>          ENQUEUE_ERROR              =3D 6
>          OTHERS                     =3D 7.
>
> Regards,
>
>
> Daniel.
>
>
>  --- "Raskin, Alon (Soliance)"
> <ARaskin at cps-satx.com>
> escribis: > Hi Daviel,
> >
> > Here is an old email that Jocelyn Dart (thanks
> > Jocelyn!) sent me a while
> > back regarding this issue.
> >
> > Regards,
> >
> > Alon Raskin
> >
> >
> > Hi Alon,
> > There are a series of API function modules for
> > SAPOffice that you can
> > use to do this. e.g. SO_DOCUMENT_INSERT_API.
> >
> > You need as a minimum a folder, the document type
> > and the document data.
> >
> > For an object the document type is OBJ.
> >
> > Fill the document_data parameter, field
> description
> > with the title of the
> > document.
>
=3D=3D=3D message truncated =3D=3D=3D
 
_______________________________________________________________
Do You Yahoo!?
Yahoo! Messenger
Comunicacisn instantanea gratis con tu gente.
http://messenger.yahoo.es
 


More information about the SAP-WUG mailing list