Skip to Content
author's profile photo Former Member
Former Member

How to attach a file that exisiting in server to email

Hi all,

I have to attach a file from server to email .I need not to upload that file i just want to attach the file which is in the server to email (.TXT format) .can any one help me in this issue?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 03:45 PM

    Hi all,

    I have cheked many threads but i found attachment from internal table .if file already existing in the server how attach that file to outlook?can any please post the sample code ?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 03:50 PM

    Hi Priya,

    Try using this Function Module 'SO_NEW_DOCUMENT_SEND_API1'.This Function module is used for sending documents as attacthments.

    Hope it helps,

    Swathi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 04:29 PM

    If you are very sure about the location of the file in the srever then u can upload it into an internal table and then from the internal table you create the attachment. This will work if ur file is just a data file.

    Regards,

    Barath.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 03:49 PM

    yes u can . Check out the code below. This is not my code and i found this from net and this is the code that i use as reference when i go for mailing programs.This code will help u to send PDF & TIFF . U can always modify the file type. The comments will not be in english but u can understand from the program flow.

    FORM ENVIAMENT_CORREU

    USING PAGINA1

    PAGINA2.

    DATA: FRONTEND_SERVICES TYPE REF TO CL_GUI_FRONTEND_SERVICES.

    DATA: T_PDF TYPE TABLE OF SOLI, "Contingut del .pdf

    T_TIF TYPE TABLE OF SOLI, "Contingut del .tif

    T_ANN TYPE TABLE OF SOLI. "Suma d'annexos

    DATA: L_ANN TYPE SOLI. "Línia estandard d'un annex

    DATA: TAM_PDF TYPE I, "Línies del .pdf

    TAM_TIF TYPE I, "Línies del .tif

    TAM_ANN TYPE I. "Línies dels annexos

    DATA: ELPATH TYPE STRING. "Per convertir tipus

    DATA: NOMFITXER(255) TYPE C, "Per separar nom i extensió

    EXTENSIO(3) TYPE C, "Extensió/tipus del fitxer

    ESBORRAR(128) TYPE C. "Per esborrar

    DATA: TEXTS LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,

    LIN_TEXT TYPE I.

    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE.

    DATA: DOC_CHNG LIKE SODOCCHGI1.

    DATA: ENVIAT LIKE SONV-FLAG.

    DATA: REMITENT LIKE SOEXTRECI1-RECEIVER,

    DADESUSER TYPE TABLE OF BAPIADSMTP WITH HEADER LINE,

    BAPIRETUR TYPE TABLE OF BAPIRET2 WITH HEADER LINE.

    • ------------------ ANNEXOS -------------------

    • 1 - el .pdf

    ELPATH = PAGINA1. "Canvi de tipus

    • Fem servir objectes perquè la funció GUI_UPLOAD

    • ens la dona com a obsoleta. Encara que el mètode

    • cridat la fa servir, és de suposar que quan SAP

    • elimini la funció, canviarà el mètode.

    IF FRONTEND_SERVICES IS INITIAL.

    CREATE OBJECT FRONTEND_SERVICES.

    ENDIF.

    CALL METHOD FRONTEND_SERVICES->GUI_UPLOAD

    EXPORTING

    FILENAME = ELPATH

    FILETYPE = 'BIN'

    READ_BY_LINE = ' '

    IMPORTING

    FILELENGTH = TAM_PDF

    CHANGING

    DATA_TAB = T_PDF

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    NOT_SUPPORTED_BY_GUI = 17

    OTHERS = 18.

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    • 2 - el .tif (o el que sigui)

    ELPATH = PAGINA2. "Canvi de tipus

    • Fem servir objectes perquè la funció GUI_UPLOAD

    • ens la dona com a obsoleta. Encara que el mètode

    • cridat la fa servir, és de suposar que quan SAP

    • elimini la funció, canviarà el mètode.

    IF FRONTEND_SERVICES IS INITIAL.

    CREATE OBJECT FRONTEND_SERVICES.

    ENDIF.

    CALL METHOD FRONTEND_SERVICES->GUI_UPLOAD

    EXPORTING

    FILENAME = ELPATH

    FILETYPE = 'BIN'

    READ_BY_LINE = ' '

    IMPORTING

    FILELENGTH = TAM_TIF

    CHANGING

    DATA_TAB = T_TIF

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    NOT_SUPPORTED_BY_GUI = 17

    OTHERS = 18.

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    *----

    -


    • Acumulem annexos!

    LOOP AT T_PDF INTO L_ANN.

    APPEND L_ANN TO T_ANN.

    ENDLOOP.

    LOOP AT T_TIF INTO L_ANN.

    APPEND L_ANN TO T_ANN.

    ENDLOOP.

    • Tamanys

    DESCRIBE TABLE T_PDF LINES TAM_PDF.

    DESCRIBE TABLE T_TIF LINES TAM_TIF.

    DESCRIBE TABLE T_ANN LINES TAM_ANN.

    • Remitent i Text del correu

    SELECT SINGLE *

    INTO T_DESTI

    FROM ZMAILDEST

    WHERE TCODE = SY-TCODE

    AND ZCOMPT = 0.

    IF SY-SUBRC = 0.

    REMITENT = T_DESTI-ZDESTI.

    IF T_DESTI-ZTEXT1 IS NOT INITIAL.

    TEXTS = T_DESTI-ZTEXT1.

    ELSE.

    TEXTS = 'Adjunt trameto l''expedient indicat.'.

    ENDIF.

    APPEND TEXTS.

    IF T_DESTI-ZTEXT2 IS NOT INITIAL.

    TEXTS = T_DESTI-ZTEXT2.

    APPEND TEXTS.

    ENDIF.

    IF T_DESTI-ZTEXT3 IS NOT INITIAL.

    TEXTS = T_DESTI-ZTEXT3.

    APPEND TEXTS.

    ENDIF.

    ELSE.

    • Busquem adreça de l'usuari

    CALL FUNCTION 'BAPI_USER_GET_DETAIL'

    EXPORTING

    USERNAME = SY-UNAME

    TABLES

    RETURN = BAPIRETUR

    ADDSMTP = DADESUSER.

    READ TABLE BAPIRETUR WITH KEY TYPE = 'E'.

    IF SY-SUBRC NE 4.

    MESSAGE E039 WITH

    'No es pot determinar remitent. Enviament avortat.'.

    ELSE.

    • trobat

    READ TABLE DADESUSER INDEX 1.

    REMITENT = DADESUSER-E_MAIL.

    ENDIF.

    • Si venim per aquí, no tenim text especificat...

    TEXTS = 'Adjunt trameto l''expedient indicat.'.

    APPEND TEXTS.

    ENDIF.

    DESCRIBE TABLE TEXTS LINES LIN_TEXT.

    • Assumpte

    CONCATENATE 'TB Núm. Expedient:'

    ZACEXPEDI-NUMEXPED

    INTO TEXTS SEPARATED BY SPACE.

    DOC_CHNG-OBJ_NAME = 'URGENT'.

    DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

    DOC_CHNG-OBJ_DESCR = TEXTS.

    DOC_CHNG-SENSITIVTY = 'O'.

    DOC_CHNG-DOC_SIZE = LIN_TEXT * 255.

    • Capçalera

    CLEAR OBJPACK-TRANSF_BIN.

    OBJPACK-HEAD_START = 1.

    OBJPACK-HEAD_NUM = 0.

    OBJPACK-BODY_START = 1.

    OBJPACK-BODY_NUM = LIN_TEXT.

    OBJPACK-DOC_TYPE = 'RAW'.

    APPEND OBJPACK.

    • Annex 1

    • Separem nom i extensió per tal d'obtenir els tipus

    NOMFITXER = PAGINA1.

    CALL FUNCTION 'SPLIT_FILENAME'

    EXPORTING

    LONG_FILENAME = NOMFITXER

    IMPORTING

    PURE_EXTENSION = EXTENSIO.

    OBJPACK-TRANSF_BIN = 'X'.

    OBJPACK-HEAD_START = 1.

    OBJPACK-HEAD_NUM = 1.

    OBJPACK-BODY_START = 1.

    OBJPACK-BODY_NUM = TAM_PDF.

    OBJPACK-DOC_TYPE = EXTENSIO.

    OBJPACK-OBJ_NAME = 'pagina1'.

    CONCATENATE 'pagina1' EXTENSIO

    INTO NOMFITXER SEPARATED BY '.'. "un altre cop junts

    OBJPACK-OBJ_DESCR = NOMFITXER.

    OBJPACK-DOC_SIZE = TAM_PDF * 255.

    APPEND OBJPACK.

    • Annex 2

    • Separem nom i extensió per tal d'obtenir els tipus

    NOMFITXER = PAGINA2.

    CALL FUNCTION 'SPLIT_FILENAME'

    EXPORTING

    LONG_FILENAME = NOMFITXER

    IMPORTING

    PURE_EXTENSION = EXTENSIO.

    OBJPACK-TRANSF_BIN = 'X'.

    OBJPACK-HEAD_START = 2.

    OBJPACK-HEAD_NUM = 2.

    OBJPACK-BODY_START = TAM_PDF + 1.

    OBJPACK-BODY_NUM = TAM_TIF.

    OBJPACK-DOC_TYPE = EXTENSIO.

    OBJPACK-OBJ_NAME = 'pagina2'.

    CONCATENATE 'pagina2' EXTENSIO

    INTO NOMFITXER SEPARATED BY '.'. "un altre cop junts

    OBJPACK-OBJ_DESCR = NOMFITXER.

    OBJPACK-DOC_SIZE = TAM_TIF * 255.

    APPEND OBJPACK.

    • VLR - 13/04/2005

    • Canvi per funció SO_DOCUMENT_SEND_API1

    • és una funció obsoleta, però ens permet canviar

    • el remitent

    *----

    -


    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = DOC_CHNG

    PUT_IN_OUTBOX = 'X'

    SENDER_ADDRESS = REMITENT

    SENDER_ADDRESS_TYPE = 'SMTP'

    COMMIT_WORK = ' '

    IMPORTING

    SENT_TO_ALL = ENVIAT

    • NEW_OBJECT_ID =

    • SENDER_ID =

    TABLES

    PACKING_LIST = OBJPACK

    • OBJECT_HEADER =

    CONTENTS_BIN = T_ANN

    CONTENTS_TXT = TEXTS

    • CONTENTS_HEX =

    • OBJECT_PARA =

    • OBJECT_PARB =

    RECEIVERS = DESTINATARIS

    EXCEPTIONS

    TOO_MANY_RECEIVERS = 1

    DOCUMENT_NOT_SENT = 2

    DOCUMENT_TYPE_NOT_EXIST = 3

    OPERATION_NO_AUTHORIZATION = 4

    PARAMETER_ERROR = 5

    X_ERROR = 6

    ENQUEUE_ERROR = 7

    OTHERS = 8.

    • CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    • EXPORTING

    • DOCUMENT_DATA = DOC_CHNG

    • PUT_IN_OUTBOX = 'X'

    • COMMIT_WORK = 'X'

    • IMPORTING

    • SENT_TO_ALL = ENVIAT

    • NEW_OBJECT_ID =

  • TABLES

  • PACKING_LIST = OBJPACK

    • OBJECT_HEADER =

  • CONTENTS_BIN = T_ANN

  • CONTENTS_TXT = TEXTS

    • CONTENTS_HEX =

    • OBJECT_PARA =

    • OBJECT_PARB =

  • RECEIVERS = DESTINATARIS

  • EXCEPTIONS

  • TOO_MANY_RECEIVERS = 1

  • DOCUMENT_NOT_SENT = 2

  • DOCUMENT_TYPE_NOT_EXIST = 3

  • OPERATION_NO_AUTHORIZATION = 4

  • PARAMETER_ERROR = 5

  • X_ERROR = 6

  • ENQUEUE_ERROR = 7

  • OTHERS = 8.

  • IF SY-SUBRC <> 0.

    MESSAGE E041

    WITH '(' SY-SUBRC ') No s''ha pogut enviar el correu.'.

    ENDIF.

    • Esborrem annexos

    ESBORRAR = PAGINA1(128).

    CALL FUNCTION 'GUI_DELETE_FILE'

    EXPORTING

    FILE_NAME = ESBORRAR

    EXCEPTIONS

    FAILED = 1

    OTHERS = 2.

    ESBORRAR = PAGINA2(128).

    CALL FUNCTION 'GUI_DELETE_FILE'

    EXPORTING

    FILE_NAME = ESBORRAR

    EXCEPTIONS

    FAILED = 1

    OTHERS = 2.

    ENDFORM. "enviament_correu

Add a comment
10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 04:07 PM

    Here goes another example . This may help u better . Just copy and execute by changing the file name and receiver mail id.

    report y_cr17_mail .

    data method1 like sy-ucomm.

    data g_user like soudnamei1.

    data g_user_data like soudatai1.

    data g_owner like soud-usrnam.

    data g_receipients like soos1 occurs 0 with header line.

    data g_document like sood4 .

    data g_header like sood2.

    data g_folmam like sofm2.

    data g_objcnt like soli occurs 0 with header line.

    data g_objhead like soli occurs 0 with header line.

    data g_objpara like selc occurs 0 with header line.

    data g_objparb like soop1 occurs 0 with header line.

    data g_attachments like sood5 occurs 0 with header line.

    data g_references like soxrl occurs 0 with header line.

    data g_authority like sofa-usracc.

    data g_ref_document like sood4.

    data g_new_parent like soodk.

    data: begin of g_files occurs 10 ,

    text(4096) type c,

    end of g_files.

    data : fold_number(12) type c,

    fold_yr(2) type c,

    fold_type(3) type c.

    parameters ws_file(4096) type c default

    'D:\Documents and Settings\n110027.UK\Desktop\SES2_mat1.txt'.

    • Can be any file fromyour pc ....either xls or word or ppt etc ...

    g_user-sapname = sy-uname.

    call function 'SO_USER_READ_API1'

    exporting

    user = g_user

    • PREPARE_FOR_FOLDER_ACCESS = ' '

    importing

    user_data = g_user_data

    • EXCEPTIONS

    • USER_NOT_EXIST = 1

    • PARAMETER_ERROR = 2

    • X_ERROR = 3

    • OTHERS = 4

    .

    if sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    endif.

    fold_type = g_user_data-outboxfol+0(3).

    fold_yr = g_user_data-outboxfol+3(2).

    fold_number = g_user_data-outboxfol+5(12).

    clear g_files.

    refresh : g_objcnt,

    g_objhead,

    g_objpara,

    g_objparb,

    g_receipients,

    g_attachments,

    g_references,

    g_files.

    method1 = 'SAVE'.

    g_document-foltp = fold_type.

    g_document-folyr = fold_yr.

    g_document-folno = fold_number.

    g_document-objtp = g_user_data-object_typ.

    *g_document-OBJYR = '27'.

    *g_document-OBJNO = '000000002365'.

    *g_document-OBJNAM = 'MESSAGE'.

    g_document-objdes = 'Barath testing by program'.

    g_document-folrg = 'O'.

    *g_document-okcode = 'CHNG'.

    g_document-objlen = '0'.

    g_document-file_ext = 'TXT'.

    g_header-objdes = 'Manohar testing by program'.

    g_header-file_ext = 'TXT'.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

    exporting

    method = method1

    office_user = sy-uname

    ref_document = g_ref_document

    new_parent = g_new_parent

    importing

    authority = g_authority

    tables

    objcont = g_objcnt

    objhead = g_objhead

    objpara = g_objpara

    objparb = g_objparb

    recipients = g_receipients

    attachments = g_attachments

    references = g_references

    files = g_files

    changing

    document = g_document

    header_data = g_header

    • FOLMEM_DATA =

    • RECEIVE_DATA =

    .

    • File from the pc to send...

    method1 = 'ATTCREATEFROMPC'.

    g_files-text = ws_file.

    append g_files.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

    exporting

    method = method1

    office_user = g_owner

    ref_document = g_ref_document

    new_parent = g_new_parent

    importing

    authority = g_authority

    tables

    objcont = g_objcnt

    objhead = g_objhead

    objpara = g_objpara

    objparb = g_objparb

    recipients = g_receipients

    attachments = g_attachments

    references = g_references

    files = g_files

    changing

    document = g_document

    header_data = g_header

    .

    method1 = 'SEND'.

    g_receipients-recnam = 'MK085'.

    g_receipients-recesc = 'B'.

    g_receipients-sndex = 'X'.

    append g_receipients.

    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

    exporting

    method = method1

    office_user = g_owner

    ref_document = g_ref_document

    new_parent = g_new_parent

    importing

    authority = g_authority

    tables

    objcont = g_objcnt

    objhead = g_objhead

    objpara = g_objpara

    objparb = g_objparb

    recipients = g_receipients

    attachments = g_attachments

    references = g_references

    files = g_files

    changing

    document = g_document

    header_data = g_header.

    Reward points if useful.

    Regards,

    Rajbarath.

    Add a comment
    10|10000 characters needed characters exceeded

  • Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.