Shell Script to send email with .txt file as attachment

Dear Al,
Could any one help me with code, for sending email with .txt file as attachment using shell script.
Thank You!

978334 wrote:
Dear Al,
Could any one help me with code, for sending email with .txt file as attachment using shell script.
Thank You!http://bit.ly/XHfSCz
https://forums.oracle.com/forums/search.jspa?threadID=&q=sendmail&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein

Similar Messages

  • Send email with txt file as attachment

    Hi ,
    can any one help me in download as txt file using the function module SO_OBJECT_SEND along with email .
    a sample code using this function module would be helpfull.
    Thanks,
    vinay .

    Hi vinay,
    Not only TXT file, u can send any
    other file like word,excel,pdf,exe, etc.
    1. There is some trick involved
    in the binary files.
    2. I have made a program (and it works fantastic)
    ONLY 6 LINES FOR EMAILING
    BELIEVE ME
    ITS A FANTASTIC PROGRAM.
    IT WILL WORK LIKE OUTLOOK EXPRESS !
    3. The user is provided with
    a) file name
    b) email address to send mail
    and it sends ANY FILE (.xls,.pdf .xyz..)
    Instantaneously !
    4. Make two things first :
    1. Include with the name : ZAMI_INCLFOR_MAIL
    2. Report with the name : ZAM_TEMP147 (any name will do)
    3. Activate both and execute (2)
    4. After providing filename, email adress
    5. Code for Include :
    10.08.2005 Amit M - Created
    Include For Mail (First Req F16)
    Modification Log
    Data
    DATA: docdata LIKE sodocchgi1,
    objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
    objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
    objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
    objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
    objhex LIKE solix OCCURS 10 WITH HEADER LINE,
    reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    DATA: tab_lines TYPE i,
    doc_size TYPE i,
    att_type LIKE soodk-objtp.
    DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
    FORM
    FORM ml_customize USING objname objdesc.
    Clear Variables
    CLEAR docdata.
    REFRESH objpack.
    CLEAR objpack.
    REFRESH objhead.
    REFRESH objtxt.
    CLEAR objtxt.
    REFRESH objbin.
    CLEAR objbin.
    REFRESH objhex.
    CLEAR objhex.
    REFRESH reclist.
    CLEAR reclist.
    REFRESH listobject.
    CLEAR listobject.
    CLEAR tab_lines.
    CLEAR doc_size.
    CLEAR att_type.
    Set Variables
    docdata-obj_name = objname.
    docdata-obj_descr = objdesc.
    ENDFORM. "ml_customize
    FORM
    FORM ml_addrecp USING preceiver prec_type.
    CLEAR reclist.
    reclist-receiver = preceiver.
    reclist-rec_type = prec_type.
    APPEND reclist.
    ENDFORM. "ml_customize
    FORM
    FORM ml_addtxt USING ptxt.
    CLEAR objtxt.
    objtxt = ptxt.
    APPEND objtxt.
    ENDFORM. "ml_customize
    FORM
    FORM ml_prepare USING bypassmemory whatatt_type whatname.
    IF bypassmemory = ''.
    Fetch List From Memory
    CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
    listobject = listobject
    EXCEPTIONS
    OTHERS = 1.
    IF sy-subrc <> 0.
    MESSAGE ID '61' TYPE 'E' NUMBER '731'
    WITH 'LIST_FROM_MEMORY'.
    ENDIF.
    CALL FUNCTION 'TABLE_COMPRESS'
    IMPORTING
    COMPRESSED_SIZE =
    TABLES
    in = listobject
    out = objbin
    EXCEPTIONS
    OTHERS = 1
    IF sy-subrc <> 0.
    MESSAGE ID '61' TYPE 'E' NUMBER '731'
    WITH 'TABLE_COMPRESS'.
    ENDIF.
    ENDIF.
    Header Data
    Already Done Thru FM
    Main Text
    Already Done Thru FM
    Packing Info For Text Data
    DESCRIBE TABLE objtxt LINES tab_lines.
    READ TABLE objtxt INDEX tab_lines.
    docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = tab_lines.
    objpack-doc_type = 'TXT'.
    APPEND objpack.
    Packing Info Attachment
    att_type = whatatt_type..
    DESCRIBE TABLE objbin LINES tab_lines.
    READ TABLE objbin INDEX tab_lines.
    objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
    objpack-transf_bin = 'X'.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = tab_lines.
    objpack-doc_type = att_type.
    objpack-obj_name = 'ATTACHMENT'.
    objpack-obj_descr = whatname.
    APPEND objpack.
    Receiver List
    Already done thru fm
    ENDFORM. "ml_prepare
    FORM
    FORM ml_dosend.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = docdata
    put_in_outbox = 'X'
    commit_work = 'X' "used from rel. 6.10
    IMPORTING
    SENT_TO_ALL =
    NEW_OBJECT_ID =
    TABLES
    packing_list = objpack
    object_header = objhead
    contents_bin = objbin
    contents_txt = objtxt
    CONTENTS_HEX = objhex
    OBJECT_PARA =
    object_parb =
    receivers = reclist
    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 ID 'SO' TYPE 'S' NUMBER '023'
    WITH docdata-obj_name.
    ENDIF.
    ENDFORM. "ml_customize
    FORM
    FORM ml_spooltopdf USING whatspoolid.
    DATA : pdf LIKE tline OCCURS 0 WITH HEADER LINE.
    Call Function
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
    EXPORTING
    src_spoolid = whatspoolid
    TABLES
    pdf = pdf
    EXCEPTIONS
    err_no_otf_spooljob = 1
    OTHERS = 12.
    Convert
    PERFORM doconv TABLES pdf objbin.
    ENDFORM. "ml_spooltopdf
    FORM
    FORM doconv TABLES
    mypdf STRUCTURE tline
    outbin STRUCTURE solisti1.
    Data
    DATA : pos TYPE i.
    DATA : len TYPE i.
    Loop And Put Data
    LOOP AT mypdf.
    pos = 255 - len.
    IF pos > 134. "length of pdf_table
    pos = 134.
    ENDIF.
    outbin+len = mypdf(pos).
    len = len + pos.
    IF len = 255. "length of out (contents_bin)
    APPEND outbin.
    CLEAR: outbin, len.
    IF pos < 134.
    outbin = mypdf+pos.
    len = 134 - pos.
    ENDIF.
    ENDIF.
    ENDLOOP.
    IF len > 0.
    APPEND outbin.
    ENDIF.
    ENDFORM. "doconv
    CODE FOR PROGRAM
    5.
    REPORT zam_temp147 .
    INCLUDE zami_inclfor_mail.
    DATA
    DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
    DATA : file_name TYPE string.
    data : path like PCFILE-PATH.
    data : extension(5) type c.
    data : name(100) type c.
    SELECTION SCREEN
    PARAMETERS : receiver TYPE somlreci1-receiver lower case.
    PARAMETERS : p_file LIKE rlgrap-filename
    OBLIGATORY.
    AT SELECTION SCREEN
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CLEAR p_file.
    CALL FUNCTION 'F4_FILENAME'
    IMPORTING
    file_name = p_file.
    START-OF-SELECTION
    START-OF-SELECTION.
    PERFORM ml_customize USING 'Tst' 'Testing'.
    PERFORM ml_addrecp USING receiver 'U'.
    PERFORM upl.
    PERFORM doconv TABLES itab objbin.
    PERFORM ml_prepare USING 'X' extension name.
    PERFORM ml_dosend.
    SUBMIT rsconn01
    WITH mode EQ 'INT'
    AND RETURN.
    FORM
    FORM upl.
    file_name = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = file_name
    filetype = 'BIN'
    TABLES
    data_tab = itab
    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
    OTHERS = 17.
    path = file_name.
    CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
    EXPORTING
    complete_filename = path
    CHECK_DOS_FORMAT =
    IMPORTING
    DRIVE =
    EXTENSION = extension
    NAME = name
    NAME_WITH_EXT =
    PATH =
    EXCEPTIONS
    INVALID_DRIVE = 1
    INVALID_EXTENSION = 2
    INVALID_NAME = 3
    INVALID_PATH = 4
    OTHERS = 5
    ENDFORM. "upl
    regards,
    amit m.

  • Why is gmail blocking me from sending email with a "pages" document attached?

    Why is gmail blocking me from sending email with a "pages" document attached? I've checked the document for viruses with "MacKeeper" and it's clean.

    Google reads your emails, in case you did not know that. Unless you are sending an email containing content Google can extract and add to its vast database of personal information, Google has no use for it.
    Google Mail is becoming progressively useless. It won't accept .zip attachments, at least not the last time I tried, it will eventually prevent you from using an email client unless you visit their web mail interface, and it will disable your account if you attempt to log in from someplace Google deems is not where Google thinks you ought to be.
    Gmail is worth every cent you paid.
    Get rid of MacKeeper. It is capable of doing nothing beneficial and will only cause problems.

  • To send email with editable PDF/XLS attachment

    Hi All,
      Is it possible to send editable PDF/XLS attachment in a mail to the customer via SAP, if yes how?
    Please Help! Urgent

    hi,
    *Sending mail with attachment
    * This program will allowed you to send email with attachment.
    * First, specify the attachment file from your local hardisk and execute.
    * Next, specify the sender email address and click the send button.
    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 'c:\debugger.txt'.
    * Can me 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   = 'sap-img.com testing by program'.
    g_document-folrg   = 'O'.
    *g_document-okcode   = 'CHNG'.
    g_document-objlen = '0'.
    g_document-file_ext = 'TXT'.
    g_header-objdes =  'sap-img.com 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.
    *-- End of Program  
    Hope this helps, Do reward.

  • Sending emails with both body and attachment to multiple recipients

    I have a requirement to send email with body and attachment to multiple recipients.
    Body of the email is a standard text. It is a proxy-to-mail scenario.
    Here is what I've done: (I'm using PI 7.11)
    One mapping from Source to Target structure (format of the attachment text file)
    Second mapping from Target Structure to Mail Package format.
    In the second mapping I'm concatenating the output of first step into "Content" of the Mail Package.
    "XIPAYLOAD" is the message protocol used.
    The "Keep attachments" option in the Mail adapter allows only to send "Content" as attachment or as body of the email.
    How to send an email with both content and text?
    The other problem is even with using ASMA, I can't send email to multiple recipients. I can only do CC and TO for 1 person each - a total of 2. Although I can resolve this by creating mailing lists, it is better if this can be addressed in PI.
    Thanks for any input you can provide!
    Edited by: crazylad on Jan 18, 2012 3:39 PM

    Thank you for your response Mikael.
    For the first question, I was able to find the solution in the following blog:
    XI Mail Adapter : Dynamically building attachment and message body content using a simple UDF
    (I just needed to search with the right set of key words )
    The key is to set the "Content Encoding" as "None" in the mail adapter. If this is not done, the mail will be sent with an attachment - untitled.bin containing both the mail body and the attachment text. Also, don't forget to check the "Keep Attachments" checkbox in the mail adapter.
    Multiple recipients could be added by separating the email IDs with a Comma. I have used ASMA to set the recipients.

  • Can't send email with large (over 1MB) attachment

    Win 7 64-bit, Thunderbird 31.2.0, eSet antivirus (but disabling it for email doesn't help), godaddy email server (works fine from godaddy web mail), port 80 (been using this port for years; 25 doesn't work)
    Sending email with a 974KB attachment works. Email with a 1.4MB (and larger) attachment doesn't work. The error message appears pretty quickly (5 seconds at the most).
    The message is "the connection to SMTP server smtpout.secureserver.net timed out".
    This problem seem to appear at random, then go away and all is well (for a while).

    No. The modem is an Arris obtained from Comcast on 6/9/2014 after the prior one failed.

  • Sending email with 1-2 MB attachment

    Why sending email with small attachment in iPad IOS7 feels like waiting for a flight delay without announcement ?
    Very embarrassing for Apple to missed this issue....
    Internet connection is fine, but email could not get through the outbox.... Oh my God...

    Hey,
    Many people have expirienced this...
    The problem for most people were their, internet connection, or their device.
    This might not work, for some people.
    I would recommend holding down the power button and the home button until the apple logo shows up.
    Then you can open mail and send your attachment, hopefully.
    If that was successfull, have a good evening!
    -- Shamurocks45

  • Script to send email with the filename of the file just added to a folder?

    Hi,
    I have an AppleScript set into an Automator workflow which will send me an email when a file is added to a folder.
    What I would like to have happen though is have the email include the file name of the file that is added to the folder
    tell application "Mail"
        set theNewMessage to make new outgoing message with properties {subject:"New File added", content:"File", visible:true}
        tell theNewMessage
            make new to recipient at end of to recipients with properties {address:"[email protected]"}
            send
        end tell
    end tell
    I'm new at the whole AppleScript thing, but I'm getting how powerful it can be.
    Thanks for any help.

    Maybe something along these lines...
    *set theBody to text returned of (display dialog "Enter message text here " default answer "")*
    *set theSubject to text returned of (display dialog "Enter subject here " default answer "")*
    *set theTarget to text returned of (display dialog "Enter recipient's email address here " default answer "")*
    *tell application "Mail"*
    *set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}*
    *tell newMessage*
    *make new to recipient at end of to recipients with properties {address:theTarget}*
    *set sender to "[email protected]"*
    *end tell*
    *send newMessage*
    *end tell*
    Regards, Andrew99

  • Problem while passing parameter to shell script which sends email-Ora Apps

    Hi,
    I have a pl/sql package which will call a shell script program.The shell script program is written in order to send the invoice hold details of AP as a mail.The parameters to this program are passed in the pl/sql package.
    The shell script program has
    5 parameters namely
    to - email
    from - email
    hold id - which is a number
    hold name - varchar2( free text)
    hold reason - varchar2( free text)
    the shell script looks as below.
    FROM_EMAIL=`echo $1|cut -f9 -d " "|sed 's/\"//g'`
    echo "From email id is $FROM_EMAIL" -- From email
    TO_EMAIL=`echo $1|cut -f10 -d " "|sed 's/\"//g'`
    echo "To Email id is $TO_EMAIL" -- to email
    PARAM0=`echo $1 | awk '{print $11}'|sed -e "s/\"//g"`
    echo "Param0: $PARAM0" -- hold id
    PARAM1=`echo "$1" | cut -d" " -f12-| sed -e "s/\" \"/\"^\"/g" | awk -F'^' '{print $1}'|sed -e "s/\"//g"`
    echo "Param1: $PARAM1" -- hold name
    PARAM2=`echo "$1" | cut -d" " -f13-| sed -e "s/\" \"/\"^\"/g" | awk -F'^' '{print $1}'|sed -e "s/\"//g"`
    echo "Param2: $PARAM2" -- hold reason
    the values that am passinf to this program are if suppose
    from email ---- [email protected]
    to email [email protected]
    12345 ------ hold id
    test hold name ------ hold name
    test hold reason ------- hold reason
    The output for the above parameters is as follows
    from email ---- [email protected]
    to email [email protected]
    12345 ------ hold id
    test hold name ------ hold name
    hold name --------hold reason (a part of hold name parameter is displayed as hold reason.The reason being in param2 we used cut which is cutting from 13.
    the problem here is since param1 being free text we cannot predict at what position the parameter ends.i mean there might be a single word or more than 2 words in that parameter seperated by space. the question here is ... is there anyway that we can specify dynamically from which location the param2 should fetch the value.
    can we use some delimiter to identify the end of param1 and start of param2.If so... how can it be written in this scenario.
    Thanks in Advance.

    As I see, all parameters are merged into 1 at shell script.
    Please do as follow:
    1- Modify your shell script as followed:
    echo "From email id is $1" -- From email
    echo "To Email id is $2" -- to email
    echo "Param0: $3" -- hold id
    echo "Param1: $4" -- hold name
    echo "Param2: $5" -- hold reason
    2- rename your shell script file with .prog extension : CUSTOM_NAME.prog
    3- perform the following command at custom file location:
    ln -s $FND_TOP/bin/fndcpesr CUSTOM_NAME
    This approach will seperate your parameters and then it will be more easier to manipulate them.
    Regards

  • How to use UTL_SMTP to send email with existing file attachment

    Hello! I am trying to create a pl/sql procedure that lets me send an email and include an existing file to a email address. So far, I found information on how to send a file and create an attachment with information I put in the procedure. This is NOT what I'm trying to do. I'm trying to send an email and include an attachment for a file that already exists. I need the pre-existing file to be sent to the email recipient.
    This is how far I've gotten, but this only allows me to CREATE an attachment with the information I put in it from the procedure. I got it from the following site:
    http://www.orafaq.com/wiki/Send_mail_from_PL/SQL
    DECLARE
       v_From       VARCHAR2(80) := '[email protected]';
       v_Recipient  VARCHAR2(80) := '[email protected]';
       v_Subject    VARCHAR2(80) := 'Weekly Invoice Report';
       v_Mail_Host  VARCHAR2(30) := 'mail.mycompany.com';
       v_Mail_Conn  utl_smtp.Connection;
       crlf         VARCHAR2(2)  := chr(13)||chr(10);
    BEGIN
      v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
      utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
      utl_smtp.Mail(v_Mail_Conn, v_From);
      utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
      utl_smtp.Data(v_Mail_Conn,
        'Date: '   || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
        'From: '   || v_From || crlf ||
        'Subject: '|| v_Subject || crlf ||
        'To: '     || v_Recipient || crlf ||
        'MIME-Version: 1.0'|| crlf ||     -- Use MIME mail standard
        'Content-Type: multipart/mixed;'|| crlf ||
        ' boundary="-----SECBOUND"'|| crlf ||
        crlf ||
        '-------SECBOUND'|| crlf ||
        'Content-Type: text/plain;'|| crlf ||
        'Content-Transfer_Encoding: 7bit'|| crlf ||
        crlf ||
        'This is a test'|| crlf ||     -- Message body
        'of the email attachment'|| crlf ||
        crlf ||
        '-------SECBOUND'|| crlf ||
        'Content-Type: text/plain;'|| crlf ||
        ' name="ap_inv_supplier_cc10.txt"'|| crlf ||
        'Content-Transfer_Encoding: 8bit'|| crlf ||
        'Content-Disposition: attachment;'|| crlf ||
        ' filename="ap_inv_supplier_cc10.txt"'|| crlf ||
        crlf ||
        'TXT,file,attachment'|| crlf ||     -- Content of attachment  (THIS IS MY PROBLEM!  I NEED TO BE ABLE TO ATTACH AN EXISTING FILE, NOT CREATE A NEW ONE)
        crlf ||
        '-------SECBOUND--'               -- End MIME mail
      utl_smtp.Quit(v_mail_conn);
    EXCEPTION
      WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
        raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
    END;
    /

    First, you must create a directory object
    create directory ORALOAD as '/home/ldcgroup/ldccbc/'
    /Study the Prerequisites in the link I posted above, or else you will not be able to read/write files from the above directory object
    "fname" relates to the file name that you read from.
    In the code below, it is also the name of the file that you are attaching.
    Although they can be different!
    l_Output is the contents of the file.
    declare
    vInHandle  utl_file.file_type;
    flen       number;
    bsize      number;
    ex         boolean;
    l_Output   raw(32767);
    fname      varchar2(30) := 'ap_inv_supplier_cc10.txt';
    vSender    varchar2(30) := '[email protected]';
    vRecip     varchar2(30) := '[email protected]';
    vSubj      varchar2(50) := 'Weekly Invoice Report';
    vAttach    varchar2(50) := 'ap_inv_supplier_cc10.txt';
    vMType     varchar2(30) := 'text/plain; charset=us-ascii';
    begin
      utl_file.fgetattr('ORALOAD', fname, ex, flen, bsize);
      vInHandle := utl_file.fopen('ORALOAD', fname, 'R');
      utl_file.get_raw (vInHandle, l_Output);
      utl_file.fclose(vInHandle);
      utl_mail.send_attach_raw(sender       => vSender
                              ,recipients   => vRecip
                              ,subject      => vsubj
                              ,attachment   => l_Output
                              ,att_inline   => false
                              ,att_filename => fname);
    end;
    /

  • Bug sending email with Excel file (immediate reply would he helpfull)

    Hi ,
       Below is have pasted a sample code where it will sends a email along with an attachtment (xls) .where the email is working perfectly but the xls file attachtment has a blank space in the first line .
    where iam facing the problem ,
    ie there should not be any blank lines at the top .
    Please run the code one i have pasted below .u can find the bug .
    can any one help me on this .
    please have ur mail id in ( reclist-receiver ) so that u can check for the output.
    This table requires information about how the data in the
    tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are
    to be distributed to the documents and its attachments.
    DATA: objpack LIKE sopcklsti1 OCCURS  2 WITH HEADER LINE.
    This table must contain the summarized data dependent on each object type.
    SAPscript objects store information here about forms and styles,
    for example. Excel list viewer objects store the number of rows and columns
    amongst other things and PC objects store their original file name.
    DATA: objhead LIKE solisti1   OCCURS  1 WITH HEADER LINE.
    *CREATION OF INTERNAL TABLE
    DATA : BEGIN OF itobjbin OCCURS 10 ,
           vbeln type vbrp-vbeln,
           matnr type vbrp-matnr,
           werks type vbrp-werks,
           fktyp like vbrk-fktyp,
           END OF itobjbin .
    This table must contain the summarized content of the objects identified as binary objects.
    *DATA: OBJBIN  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE.
    DATA:   objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                   WITH HEADER LINE.
    DATA: wa_itobjbin LIKE itobjbin .
    This table must contain the summarized content of the objects identified as ASCII objects.
    DATA: objtxt  LIKE solisti1   OCCURS 10 WITH HEADER LINE.
    This table must contain the document recipients.
    DATA: reclist LIKE somlreci1  OCCURS  5 WITH HEADER LINE.
    This structure must contain the attributes of the document to be sent.
    DATA: doc_chng LIKE sodocchgi1.
    DATA: tab_lines LIKE sy-tabix.
    DATA : V_FKTYP LIKE VBRK-FKTYP.
    Creating the document to be sent
    doc_chng-obj_name = 'OFFER'.                      " input contains the attributes of the document to be sent
    doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD'.   "input contains title/subject of the document
    *BODY OF THE MAIL
    OBJTXT = 'Hi'.
    APPEND OBJTXT .
    OBJTXT = 'Test for excel download'.
    APPEND OBJTXT.
    OBJTXT = 'Below is the attachment with Billing Document Details'.
    APPEND OBJTXT.
    OBJTXT = 'Regards'.
    APPEND OBJTXT.
    DESCRIBE TABLE objtxt LINES tab_lines.
    READ TABLE objtxt INDEX tab_lines.
    doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
    Creating the entry for the compressed document
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num   = 0.
    objpack-body_start = 1.
    objpack-body_num   = tab_lines.
    objpack-doc_type   = 'RAW'.
    APPEND objpack.
    Creating the document attachment
    (Assume the data in OBJBIN are given in BMP format)
    select vbeln matnr werks
            from vbrp into table itobjbin
            up to 10 rows
            where werks GE '1000'.
    loop at itobjbin.
    select single fktyp into  v_fktyp from vbrk where vbeln = itobjbin-vbeln.
    move v_fktyp to itobjbin-fktyp.
    modify itobjbin.
    endloop.
    PERFORM build_xls_data_table .
    DESCRIBE TABLE objbin LINES tab_lines.
    objhead = 'ABC.XLS'. APPEND objhead.
    Creating the entry for the compressed attachment
    objpack-transf_bin = 'X'.
    objpack-head_start = 1.
    objpack-head_num   = 1.
    objpack-body_start = 1.
    objpack-body_num   = tab_lines.
    objpack-doc_type   = 'XLS'.
    objpack-obj_name   = 'ATTACHMENT'.
    objpack-obj_descr = 'XLS'.
    objpack-doc_size   = tab_lines * 255.
    APPEND objpack..
    Entering names in the distribution list
    reclist-receiver = ''.
    reclist-rec_type = 'U'.
    APPEND reclist.
    Sending the document
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
              document_data = doc_chng
              put_in_outbox = 'X'
              commit_work   = 'X'
         TABLES
              packing_list  = objpack
              object_header = objhead
              contents_bin  = objbin
              contents_txt  = objtxt
              receivers     = reclist
         EXCEPTIONS
              too_many_receivers = 1
              document_not_sent  = 2
              operation_no_authorization = 4
              OTHERS = 99.
    CASE sy-subrc.
      WHEN 0.
        WRITE: / 'Result of the send process:'.
        LOOP AT reclist.
          WRITE: / reclist-receiver(48), ':'.
          IF reclist-retrn_code = 0.
            WRITE 'sent successfully'.
          ELSE.
            WRITE 'not sent'.
          ENDIF.
        ENDLOOP.
      WHEN 1.
        WRITE: / 'no authorization to send to the specified number of',  'recipients!'.
      WHEN 2.
        WRITE: / 'document could not be sent to any of the recipients!'.
      WHEN 4.
        WRITE: / 'no authorization to send !'.
      WHEN OTHERS.
        WRITE: / 'error occurred during sending !'.
    ENDCASE.
    *&      Form  build_xls_data_table
          text
    -->  p1        text
    <--  p2        text
    FORM build_xls_data_table .
    CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
               con_tab TYPE x VALUE '09'.   "OK for non Unicode
    CONCATENATE 'Billing Document' 'Material Number' 'Plant' 'Billing category' ' ' INTO objbin SEPARATED BY con_tab.
    CONCATENATE con_cret objbin  INTO objbin.
    APPEND  objbin.
    LOOP AT itobjbin  .
       CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp' '
              INTO objbin SEPARATED BY con_tab.
       CONCATENATE con_cret objbin  INTO objbin.
       APPEND  objbin.
    ENDLOOP.
    thanks in advance,
    vinay .

    Hi ravi ,
         Thanks ,for your help .now xls is working fine .
    but now iam facing a problem with the same function module .for txt files .where all the records are formated in asingle line .
    can u provide a solution for this ,which would be very helpfull.
    below is have attached the sample code .
    Thanks,
    vinay.
    FUNCTION Z_KAILASH_ATTACHMENT1.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(EMAILID)
    *"     VALUE(SUBJECT)
    *"     VALUE(ATYPE)
    *"  TABLES
    *"      ATTACH_FILE STRUCTURE  SOLISTI1
    *"      BODY OPTIONAL
    This table requires information about how the data in the
    tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are
    to be distributed to the documents and its attachments.
      DATA OBJPACK LIKE SOPCKLSTI1 OCCURS  2 WITH HEADER LINE.
    This table must contain the summarized data dependent on each object type.
    SAPscript objects store information here about forms and styles,
    for example. Excel list viewer objects store the number of rows and columns
    amongst other things and PC objects store their original file name.
      DATA OBJHEAD LIKE SOLISTI1   OCCURS  1 WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as binary objects.
      DATA   OBJBIN TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                     WITH HEADER LINE.
    This table must contain the summarized content of the objects identified as ASCII objects.
      DATA OBJTXT  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE.
    This table must contain the document recipients.
      DATA  RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE .
    This structure must contain the attributes of the document to be sent.
      DATA: DOC_CHING LIKE SODOCCHGI1.
      DATA: TAB_LINES LIKE SY-TABIX.
    Create the internal table for body , subject
      DATA: IT_BODY LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    CONSTANTS: con_cret TYPE C VALUE cl_abap_char_utilities=>horizontal_tab,
               con_tab TYPE C VALUE cl_abap_char_utilities=>cr_lf.
    Move Body to Internal Table (body into it_body)
      LOOP AT BODY .
        MOVE BODY TO IT_BODY .
        APPEND IT_BODY .
      ENDLOOP.
      DOC_CHING-OBJ_DESCR = SUBJECT.   "Subject of the Email
    Move the Subject and Body to OBJTXT
      OBJTXT[] = IT_BODY[].
    DESCRIBE TABLE OBJTXT LINES TAB_LINES.
    READ TABLE OBJTXT INDEX TAB_LINES.
    DOC_CHING-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    CLEAR OBJPACK-TRANSF_BIN.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM   = 0.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM   = TAB_LINES.
    OBJPACK-DOC_TYPE   = 'RAW'.
    APPEND OBJPACK.
    Convert IT to Excel format
    IF ATYPE = 'XLS' .
    *CONSTANTS: con_cret TYPE C VALUE cl_abap_char_utilities=>horizontal_tab,
              con_tab TYPE C VALUE cl_abap_char_utilities=>cr_lf.
      LOOP AT ATTACH_FILE .
        REPLACE ALL OCCURRENCES OF '#' IN ATTACH_FILE WITH con_cret. "  INTO objbin.
        CONCATENATE  ATTACH_FILE con_tab INTO objbin.
        APPEND  objbin.
      ENDLOOP.
    ELSEIF ATYPE = 'TXT' .
      LOOP AT ATTACH_FILE .
        REPLACE ALL OCCURRENCES OF '#' IN ATTACH_FILE WITH con_tab. "  INTO objbin.
        CONCATENATE ATTACH_FILE ' '  INTO OBJBIN .
        APPEND OBJBIN .
      ENDLOOP.
    ENDIF.
    ****End-Code Excel Format .
    DESCRIBE TABLE objbin LINES tab_lines.
    objhead = subject. APPEND objhead.
    Creating the entry for the compressed attachment
    objpack-transf_bin = 'X'.
    objpack-head_start = 1.
    objpack-head_num   = 1.
    objpack-body_start = 1.
    objpack-body_num   = TAB_LINES.
    objpack-doc_type   = ATYPE.
    objpack-obj_name   = 'ATTACHMENT'.
    objpack-obj_descr = 'TEST'. "Attachment File Name
    objpack-doc_size   = TAB_LINES * 255.
    APPEND objpack..
    reclist-receiver = EMAILID.
    reclist-rec_type = 'U'.
    APPEND reclist.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
       DOCUMENT_DATA                    = DOC_CHING
       PUT_IN_OUTBOX                    = 'X'
       COMMIT_WORK                      = 'X'
    IMPORTING
      SENT_TO_ALL                     =
      NEW_OBJECT_ID                   =
      TABLES
        PACKING_LIST                    = OBJPACK
       OBJECT_HEADER                    = OBJHEAD
       CONTENTS_BIN                     = OBJBIN
       CONTENTS_TXT                     = OBJTXT
       RECEIVERS                        =  RECLIST
    EXCEPTIONS
       TOO_MANY_RECEIVERS               = 1
       DOCUMENT_NOT_SENT                = 2
       OPERATION_NO_AUTHORIZATION       = 4
       OTHERS                           = 99 .
    ENDFUNCTION.

  • How to send mail from linux with .txt file as attachment ..

    I want to send email from linux box and in the body of the email i want to have the content of dblog.txt file.
    I want dglob.txt file content to be part of the mail body.
    Thanks in advance!!

    Apr 29 15:19:35 lctwprddb01 sendmail[1616]: m3TJJZ4k001616: to=[email protected], ctladdr=oracle (500/500), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30109, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (m3TJJZhB001617 Message accepted for delivery)
    Apr 29 16:04:52 lctwprddb01 sendmail[1422]: m3TIP6LJ031388: to=<[email protected]>, ctladdr=<[email protected]> (500/500), delay=01:39:46, xdelay=00:48:01, mailer=esmtp, pri=120423, relay=cluster2a.us.messagelabs.com. [216.82.249.211], dsn=4.0.0, stat=Deferred: Connection timed out with cluster2a.us.messagelabs.com.
    Apr 29 16:07:36 lctwprddb01 sendmail[1619]: m3TJJZhB001617: to=<[email protected]>, ctladdr=<[email protected]> (500/500), delay=00:48:01, xdelay=00:48:01, mailer=esmtp, pri=120425, relay=cluster2a.us.messagelabs.com. [216.82.248.44], dsn=4.0.0, stat=Deferred: Connection timed out with cluster2a.us.messagelabs.com.
    Apr 29 16:07:52 lctwprddb01 sendmail[1627]: m3TILs2r031176: to=<[email protected]>, ctladdr=<[email protected]> (500/500), delay=01:45:58, xdelay=00:48:01, mailer=esmtp, pri=120429, relay=cluster2a.us.messagelabs.com. [216.82.248.45], dsn=4.0.0, stat=Deferred: Connection timed out with cluster2a.us.messagelabs.com.

  • Problem in send mail with .txt file attached

    According to the diferent checks, I found the next problems:
    1.- Between each caracters there is an space, example:(E Q U I P M E N T) and could be (EQUIPMENT), the last one is the correct form.
    2.- For example, two registers in my internal table appear in one line of my .txt file, but i want that each register of my internal table appear in differents lines of my .txt file.
    3.- The length of each register of my internal table (objbin) is 255 characters, but i really want that the length of each register of my internal table be 1023 characters.
    Thank you

    This is my perform:
    FORM z_envia_correo .
      DATA: docu_data LIKE SODOCCHGI1,
            tablines TYPE i,
            destinatarios  like somlreci1  occurs 1 with header line.
      DATA: BEGIN OF packlist OCCURS 0.
              INCLUDE STRUCTURE SOPCKLSTI1.
      DATA: END OF packlist.
      DATA: BEGIN OF objbin OCCURS 0.
              INCLUDE STRUCTURE SOLISTI1.
      DATA: END OF objbin.
      DATA: BEGIN OF object_header OCCURS 0.
              INCLUDE STRUCTURE SOLISTI1.
      DATA: END OF object_header.
      DATA: BEGIN OF contents OCCURS 0.
              INCLUDE STRUCTURE SOLISTI1.
      DATA: END OF contents.
    *-->ihv270907
      DATA: l_string TYPE string,
            l_fecha(10) TYPE c,
            l_dia(2) TYPE c,
            l_mes(2) TYPE c,
            l_ano(4) TYPE c,
            l_hora(8) TYPE c,
            l_h(2) TYPE c,
            l_min(2) TYPE c,
            l_seg(2) TYPE c.
    *<--ihv270907
    Variable del destinatario para enviar el mail
      DATA: l_usrnam TYPE string.
    *Caracter salto de linea
      FIELD-SYMBOLS <hex_container> TYPE c.
      CONSTANTS: zz_tab TYPE x VALUE '0D' LENGTH 4. "valor del salto de linea en hexadecimal
      ASSIGN zz_tab TO <hex_container> CASTING.
    cargo el texto de cabecera del mail
      CLEAR docu_data.
      docu_data-obj_name = 'ZFLOTA'.
      CONCATENATE 'ZFLOTA' sy-datum INTO docu_data-obj_descr SEPARATED BY space.
      docu_data-proc_type = 'T'.
      docu_data-proc_name = 'ZFLOTA'.
    cargo el texto del cuerpo del mail
      CLEAR contents.
    *-->ihv270907
      l_string = TEXT-I04.
      REPLACE '&' IN l_string WITH sy-uname.
      l_ano = sy-datum+0(4).
      l_mes = sy-datum+4(2).
      l_dia = sy-datum+6(2).
      CONCATENATE l_dia l_mes l_ano INTO l_fecha SEPARATED BY '/'.
      REPLACE '&' IN l_string WITH l_fecha.
      l_h = sy-uzeit+0(2).
      l_min = sy-uzeit+2(2).
      l_seg = sy-uzeit+4(2).
      CONCATENATE l_h l_min l_seg INTO l_hora SEPARATED BY ':'.
      REPLACE '&' IN l_string WITH l_hora.
      contents = l_string.
    *<--ihv270907
      APPEND contents.
      DESCRIBE TABLE contents LINES tablines.
      READ TABLE contents INDEX tablines.
      docu_data-doc_size = ( tablines - 1 ) * 255 + STRLEN( contents ).
    cargo el contenido del attachmet
      LOOP AT g_gt_outtab_mail.
        g_gt_outtab_mail-line+254(1) = <hex_container>.
        MOVE g_gt_outtab_mail-line TO objbin-line.
        APPEND objbin.
      ENDLOOP.
    genero el nombre del archivo a ser attachado
      CLEAR object_header.
      object_header-line = 'ZFLOTA.txt'.
      APPEND object_header.
    armo las caracteristicas del mail
      CLEAR packlist.
      packlist-head_start = 1.
      packlist-head_num = 0.
      packlist-body_start = 1.
      packlist-body_num = tablines.
      packlist-transf_bin = space.
      packlist-doc_type = 'RAW'.
      APPEND packlist.
    armo las caracteristicas del attachment
      DESCRIBE TABLE objbin LINES tablines.
      packlist-transf_bin = 'X'.
      packlist-head_start = 1.
      packlist-head_num = 0.
      packlist-body_start = 1.
      packlist-body_num = tablines.
      packlist-doc_type = 'TXT'.
      packlist-obj_name = 'ZFLOTA.txt'.
      packlist-obj_descr = 'ZFLOTA.txt'.
      packlist-doc_size = tablines * 250.
      APPEND packlist.
    Destinatarios
      l_usrnam = sy-uname.
      MOVE: l_usrnam TO destinatarios-receiver.
      destinatarios-rec_type = 'B'.   "U externo; B -> SAP
      destinatarios-sap_body = 'X'.
      APPEND DESTINATARIOS.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          DOCUMENT_DATA                    = docu_data
          PUT_IN_OUTBOX                    = 'X'
          COMMIT_WORK                      = 'X'
        TABLES
          PACKING_LIST                     = packlist
          OBJECT_HEADER                    = object_header
          CONTENTS_BIN                     = objbin
          CONTENTS_TXT                     = contents
          RECEIVERS                        = destinatarios
    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " z_envia_correo
    Thank you.

  • Send email with spool in excel attachment

    Hi,
    I have this function:
    CALL FUNCTION 'Z_SEND_EMAIL_SPOOL_PDF'
           EXPORTING
                application = 'EMAIL'
                emailtitle  = texttitle
                recextnam   = email
                src_spoolid = tsp01-rqident
           TABLES
                texttab     = body.
    And code:
    FUNCTION z_send_email_spool_pdf .
    *"*"Interfase local
    *"  IMPORTING
    *"     REFERENCE(APPLICATION) LIKE  SOOD1-OBJNAM DEFAULT 'EMAIL'
    *"     REFERENCE(EMAILTITLE) LIKE  SOOD1-OBJDES
    *"     VALUE(RECEXTNAM) LIKE  SOOS1-RECEXTNAM
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"  TABLES
    *"      TEXTTAB STRUCTURE  SOLI
    *- local data declaration
      DATA: ohd    LIKE sood1,
            oid    LIKE soodk,
            to_all LIKE sonv-flag,
            okey   LIKE swotobjid-objkey.
      DATA: g_document     LIKE sood4,
            g_header_data  LIKE sood2,
            g_authority LIKE sofa-usracc,
            lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE,
            l_folder_id    LIKE sofdk,
            l_objcont     LIKE soli OCCURS 0 WITH HEADER LINE,
            i_bin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            l_objhead     LIKE soli OCCURS 0 WITH HEADER LINE,
            folder_id      LIKE soodk,
            object_id      LIKE soodk,
            link_folder_id LIKE soodk,
            hd_dat  LIKE sood1.
      DATA: desired_type  LIKE sood-objtp,
            real_type LIKE sood-objtp,
            attach_type LIKE sood-objtp,
            otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat
            ali LIKE sood-objtp VALUE 'ALI', " ABAP lists
            pdf LIKE sood-objtp VALUE 'PDF', "PDF format
            pbyte TYPE i,
            t_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
            objtype LIKE rststype-type,
            type    LIKE rststype-type.
      CONSTANTS: ou_fol LIKE sofh-folrg              VALUE 'O',
                 c_objtp    LIKE g_document-objtp    VALUE 'RAW',
                 c_file_ext LIKE g_document-file_ext VALUE 'PDF'.
      DATA: BEGIN OF receivers OCCURS 0.
              INCLUDE STRUCTURE soos1.
      DATA: END OF receivers.
    * Fist part: Verify if the spool really exists
      SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
      CHECK sy-subrc = 0.
    *- fill odh
      CLEAR ohd.
      ohd-objla    = sy-langu.
      ohd-objnam   = application.
      ohd-objdes   = emailtitle.
      ohd-objpri   = 3.
      ohd-objsns   = 'F'.
      ohd-ownnam   = sy-uname.
    *- send Email
      CONDENSE recextnam NO-GAPS.
      CHECK recextnam <> space AND recextnam CS '@'.
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
           EXPORTING
                authority     = 'SP01'
                client        = tsp01-rqclient
                name          = tsp01-rqo1name
                part          = 1
           IMPORTING
                type          = type
                objtype       = objtype
           EXCEPTIONS
                fb_error      = 1
                fb_rsts_other = 2
                no_object     = 3
                no_permission = 4
                OTHERS        = 5.
      attach_type = c_objtp.
      desired_type = pdf.
      IF objtype(3) = 'OTF'.
        CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
             EXPORTING
                  src_spoolid   = src_spoolid
             IMPORTING
                  pdf_bytecount = pbyte
             TABLES
                  pdf           = t_pdf.
      ELSE.
        CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
             EXPORTING
                  src_spoolid   = src_spoolid
             IMPORTING
                  pdf_bytecount = pbyte
             TABLES
                  pdf           = t_pdf.
      ENDIF.
      PERFORM convertir_tabla_pdf_2 TABLES t_pdf l_objcont.
      CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
           EXPORTING
                owner     = sy-uname
                region    = ou_fol
           IMPORTING
                folder_id = l_folder_id
           EXCEPTIONS
                OTHERS    = 5.
    * fill out informations about the header of the email
      CLEAR: g_document.
      g_document-foltp     = l_folder_id-foltp.
      g_document-folyr     = l_folder_id-folyr.
      g_document-folno     = l_folder_id-folno.
      g_document-objtp     = c_objtp.
      g_document-objdes    = emailtitle.
      g_document-file_ext  = c_file_ext.
      g_header_data-objdes    = emailtitle.
      CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
           EXPORTING
                method      = 'SAVE'
                office_user = sy-uname
           IMPORTING
                authority   = g_authority
           TABLES
                objcont     = texttab
                attachments = lt_attachments
           CHANGING
                document    = g_document
                header_data = g_header_data
           EXCEPTIONS
                OTHERS      = 1.
      object_id-objtp = c_objtp.
      object_id-objyr = g_document-objyr.
      object_id-objno = g_document-objno.
      folder_id-objtp = l_folder_id-foltp.
      folder_id-objyr = l_folder_id-folyr.
      folder_id-objno = l_folder_id-folno.
      link_folder_id-objtp = l_folder_id-foltp.
      link_folder_id-objyr = l_folder_id-folyr.
      link_folder_id-objno = l_folder_id-folno.
      hd_dat-file_ext = pdf.
      hd_dat-objdes = emailtitle.
      CALL FUNCTION 'SO_ATTACHMENT_INSERT'
           EXPORTING
                object_id                  = object_id
                attach_type                = attach_type
                object_hd_change           = hd_dat
                owner                      = sy-uname
           TABLES
                objcont                    = l_objcont
                objhead                    = l_objhead
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                object_type_not_exist      = 17
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                x_error                    = 1000.
    *       FORM SO_OBJECT_SEND_REC                                       *
    FORM  so_object_send_rec
          TABLES  objcont      STRUCTURE soli
                  receivers    STRUCTURE soos1
          USING   object_hd    STRUCTURE sood1
                  folder_id
                  object_id
                  link_folder_id.
      DATA:   oid     LIKE soodk,
              to_all  LIKE sonv-flag,
              okey    LIKE swotobjid-objkey.
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                extern_address             = 'X'
    *            object_hd_change           = object_hd
    *            object_type                = 'RAW'
                outbox_flag                = 'X'
                sender                     = sy-uname
                owner                      = sy-uname
                folder_id                  = folder_id
                object_id                  = object_id
                store_flag                 = 'X'
                link_folder_id             = link_folder_id
           IMPORTING
                object_id_new              = oid
                sent_to_all                = to_all
                office_object_key          = okey
           TABLES
                objcont                    = objcont
                receivers                  = receivers
           EXCEPTIONS
                active_user_not_exist      = 1
                communication_failure      = 2
                component_not_available    = 3
                folder_not_exist           = 4
                folder_no_authorization    = 5
                forwarder_not_exist        = 6
                note_not_exist             = 7
                object_not_exist           = 8
                object_not_sent            = 9
                object_no_authorization    = 10
                object_type_not_exist      = 11
                operation_no_authorization = 12
                owner_not_exist            = 13
                parameter_error            = 14
                substitute_not_active      = 15
                substitute_not_defined     = 16
                system_failure             = 17
                too_much_receivers         = 18
                user_not_exist             = 19
                x_error                    = 20
                OTHERS                     = 21.
      IF sy-subrc <> 0.
        RAISE others.
      ENDIF.
    ENDFORM.
    *       FORM INIT_REC                                                 *
    FORM init_rec TABLES receivers STRUCTURE soos1.
      CLEAR receivers.
      REFRESH receivers.
      MOVE sy-datum  TO receivers-rcdat .
      MOVE sy-uzeit  TO receivers-rctim.
      MOVE '1'       TO receivers-sndpri.
      MOVE 'X'       TO receivers-sndex.
      MOVE 'U-'      TO receivers-recnam.
      MOVE 'U'       TO receivers-recesc.
      MOVE 'INT'     TO receivers-sndart.
      MOVE '5'       TO receivers-sortclass.
      APPEND receivers.
    ENDFORM.
    With this function I can send a spool in pdf format by email. But, now I need send a spool in Excel (xls) format by email. I try to disconnect 'CONVERT_OTFSPOOLJOB_2_PDF' and 'CONVERT_ABAPSPOOLJOB_2_PDF' but doesnt work.
    Can you help me?
    A lot of thanks in advance.
    Best regards.

    Hi.
    I do not think it is feasible to create a worthwhile Excel file from a SAP spool file.
    I have reports that send output as Excel attachments to email, but the code (including function modules etc) is too much to post here.
    You can use OLE to create an Excel file, but this will not generally work when the report is run in the background.
    So my approach is to make the report write an Excel XML file (that's just text after all), and send that as an XLS email attachment.  When the email receiver double-clicks on the attachment, it fires up Excel and brings in the data.  Most users would not realise that it's not a native Excel file.
    One nice touch is to have two sheets in the Excel file, one with the main report and the other with the selection criteria.
    Of course there is a lot of work getting started with this.
    John

  • Send EMail with *.txt as attachment.

    Hi All i have the data in the internal table and i want to send that data as attachment  for mail in  notepad format.plz send any sample program.
    the file should be in notepad format
    thanks & Regards
    vamsin

    use the below   program  and just  pass your internal table  and activate  it  ....  it will give you the attach file   of the data  in txt format  ..  see the email id  which is defualt  ... change it as  you  email id ..
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    * Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    * Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    START-OF-SELECTION.
    * Write statement to represent report output. Spool request is created
    * if write statement is executed in background. This could also be an
    * ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    PERFORM process_email.
    if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
    IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM
    FORM get_job_details.
    * Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    *  perform send_email using p_email2.
    ENDFORM.
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    *  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'TXT'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           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.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    [code]FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           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.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    reard  points if it us usefull ...
    gIRISH

Maybe you are looking for