Problem in sending attachment using "SO_NEW_DOCUMENT_ATT_SEND_API1"

Hi All,
I have a requirement of sending the data available in an internal table via email. I need to populate this content into excel sheet and send it as an attachment to recipients. I am using the following code for that.
REPORT  z51515t_doc_att.
DATA: objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: objtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng  LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA : BEGIN OF itab OCCURS 0,
          pernr LIKE p0001-pernr,
          name LIKE p0002-vorna,
       END OF itab.
Creation of the document to be sent
File Name
doc_chng-obj_name = 'SENDFILE'.
Mail Subject
doc_chng-obj_descr = 'Delivered Mail'.
Mail Contents
objtxt = 'My Content 1 '.
APPEND objtxt.
objtxt = 'My Content2'.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
Creation of the entry for the document
CLEAR objpack-transf_bin. "Will get content from content_text
objpack-head_start = 1. "Reads given row number in object header
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Prepare content for attachment
DO 3 TIMES.
  itab-pernr = 182.
  itab-name = 'Prasath'.
  APPEND itab.
  itab-pernr = 1000.
  itab-name = 'Praveen'.
  APPEND itab.
ENDDO.
Populate attachment content
LOOP AT itab.
  CONCATENATE itab-pernr itab-name INTO objbin-line.
  APPEND objbin.
ENDLOOP.
DESCRIBE TABLE objbin LINES tab_lines.
Creation of the entry for the compressed attachment
objpack-transf_bin = 'X'. "Will get content from content_bin
objpack-head_start = 1.
objpack-head_num   = 1.
objpack-body_start = 1.
objpack-body_num   = tab_lines.
objpack-doc_type   = 'EXT'.
objpack-obj_name   = 'WEBSITE'.
objpack-obj_descr  = 'MyFile.XLS'.
objpack-doc_size   = tab_lines * 255.
APPEND objpack.
target recipent
CLEAR reclist.
reclist-receiver = '[email protected]'.
reclist-express  = 'X'.
reclist-rec_type = 'U'.
APPEND reclist.
copy recipents
CLEAR reclist.
reclist-receiver = '[email protected]'.
reclist-express  = 'X'.
reclist-rec_type = 'U'.
reclist-copy     = 'X'.
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.
Now using this code i am able to send out the file but the data in the XL file is not aligned properly. When i open the attachment that i receive the contents of itab appear inside the same cell - A1 of the XL sheet. I want the data to be available in different rows and columns. How do i achieve this?
Thanks,
Prasath N

See the below program it was sending the file   as  attach in XLS  format   by  column and rows  are  properly placed ...  see the
<b>Code  in my program  :
CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x VALUE '09'.   "OK for non Unicode</b>
REPORT  ZEMAIL_ATTACH                   .
TABLES: ekko.
PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT '[email protected]'.
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
  ebeln(10) TYPE c,
  ebelp(5)  TYPE c,
  aedat(8)  TYPE c,
  matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
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,
        gd_error    TYPE sy-subrc,
        gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
*   Retrieve sample data from table ekpo
  PERFORM data_retrieval.
*   Populate table with detaisl to be entered into .xls file
  PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
  perform populate_email_message_body.
* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_message
                                      it_attach
                                using p_email
                                      'Example .xls documnet attachment'
                                      'XLS'
                                      'filename'
                             changing gd_error
                                      gd_reciever.
*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.
*&      Form  DATA_RETRIEVAL
*       Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
  SELECT ebeln ebelp aedat matnr
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
ENDFORM.                    " DATA_RETRIEVAL
*&      Form  BUILD_XLS_DATA_TABLE
*       Build data table for .xls document
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
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
*    con_cret type c value cl_abap_char_utilities=>CR_LF.
  CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
         INTO it_attach SEPARATED BY con_tab.
  CONCATENATE con_cret it_attach  INTO it_attach.
  APPEND  it_attach.
  LOOP AT it_ekpo INTO wa_charekpo.
    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                wa_charekpo-aedat wa_charekpo-matnr
           INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach  INTO it_attach.
    APPEND  it_attach.
  ENDLOOP.
ENDFORM.                    " BUILD_XLS_DATA_TABLE
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*       Send email
FORM send_file_as_email_attachment tables pit_message
                                          pit_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.
  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[] = pit_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.
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*       Instructs mail send program for SAPCONNECT to send email.
FORM initiate_mail_execute_program.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
                WITH output = 'X'
                AND RETURN.
ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
*&      Form  POPULATE_EMAIL_MESSAGE_BODY
*        Populate message body text
form populate_email_message_body.
  REFRESH it_message.
  it_message = 'Please find attached a list test ekpo records'.
  APPEND it_message.
endform.                    " POPULATE_EMAIL_MESSAGE_BODY
reward  points  if it is usefull ....
Girish

Similar Messages

  • Problem in sending attachment mail

    hi all
    i am using function module "SO_NEW_DOCUMENT_ATT_SEND_API1"
    i am facing problem in sending attachment .....if width of my text line is more than 255.
    pls guide me how to proceed further

    Hi,
    See this thread.
    Re: How to email an attachment with more than 255 characters?
    Hope it help you.
    Regards,
    Lijo Joseph

  • Problem in sending messages using java mail api

    Hi All,
    I have a problem in sending messages via java mail api.
    MimeMessage message = new MimeMessage(session);
    String bodyContent = "ñSunJava";
    message.setText (bodyContent,"utf-8");using the above code its not possible for me to send the attachment. if i am using the below code means special characters like ñ gets removed or changed into some other characters.
    MimeBodyPart messagePart = new MimeBodyPart();
                messagePart.setText(bodyText);
                // Set the email attachment file
                MimeBodyPart attachmentPart = new MimeBodyPart();
                FileDataSource fileDataSource = new FileDataSource("C:/sunjava.txt") {
                    public String getContentType() {
                        return "application/octet-stream";
                attachmentPart.setDataHandler(new DataHandler(fileDataSource));
                attachmentPart.setFileName(filename);
                Multipart multipart = new MimeMultipart();
                multipart.addBodyPart(messagePart);
                multipart.addBodyPart(attachmentPart);
                message.setContent(multipart);
                Transport.send(message);is there any way to send the file attachment with the body message without using MultiPart java class.

    Taken pretty much straight out of the Javamail examples the following works for me (mail read using Thunderbird)        // Define message
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            // Set the 'to' address
            for (int i = 0; i < to.length; i++)
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    // Set the 'cc' address
    for (int i = 0; i < cc.length; i++)
    message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
    // Set the 'bcc' address
    for (int i = 0; i < bcc.length; i++)
    message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
    message.setSubject("JavaMail With Attachment");
    // Create the message part
    BodyPart messageBodyPart = new MimeBodyPart();
    // Fill the message
    messageBodyPart.setText("Here's the file ñSunJava");
    // Create a Multipart
    Multipart multipart = new MimeMultipart();
    // Add part one
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    for (int count = 0; count < 5; count++)
    String filename = "hello" + count + ".txt";
    String fileContent = " ñSunJava - Now is the time for all good men to come to the aid of the party " + count + " \n";
    // Create another body part
    BodyPart attachementBodyPart = new MimeBodyPart();
    // Get the attachment
    DataSource source = new StringDataSource(fileContent, filename);
    // Set the data handler to this attachment
    attachementBodyPart.setDataHandler(new DataHandler(source));
    // Set the filename
    attachementBodyPart.setFileName(filename);
    // Add this part
    multipart.addBodyPart(attachementBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send(message);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Status of the mail sending option using SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi experts,
    I m using SO_NEW_DOCUMENT_ATT_SEND_API1 function moduel for sending mails to dealers. That is, whenver i execute a Z transaction, the customer invoice details are getting displayed in report output. At the same time, the same output data is sent as mail to the respective dealers.
    Now teh user is asking whether there is any possiblity for the end users to have a proof of the mail which is being sent from the Z transaction. If the mail is sent, the end user who executes the Z transaction (mail sending transaction) should have that mail in his/her SENT ITEMS. If the mail not reaches the dealer, then the user must identify the mail bounce identification.
    Pls tell me how to achve the same..
    Regards,
    Shanthi

    Hi,
    Yes it is possible..
    Just pass 'X' to the exporting parameter 'put_in_outbox'. The user can check the send mail in 'sost'. All the details of the mail will be there. This will be the proof that the mail was sent.
    Reg the 2nd part of your query, if the mail is not delivered to any reciepent or to particular recipient, the details will be there in the SAP outbox, that also you can see through transaction 'sost'.
    Thanks & Regards
    Rocky

  • Problems with sending attachements.

    Hello I've a problem with sending attachments.
    I've got mail  Version 5.0 (1244.2/1244.3) and Hosted Exchange (xs4all in the Netherlands). Most of my mail works fine (sending and receive mails).
    The most irritating problem is I cannot send messages with a attachement even 1 KB.
    Hope anyone can help?
    Ohter synchronisation Calender & contacts are even not working fine - but a cable will help. So if anyone can help there to, I will be happy.
    Thanks Vanessa

    Im having same problem with BTINTERNET account email, tbh ive had issues with this from the start. keeps going on about yahoo *** is that about... could do with someone verifying settings ive done what all the website says but same issue....attachment is only 11.7mb surely thats not an issue.......anybody know whats going on????

  • How to send attachement using JACOB

    When I am trying to send an email with attachement using JACOB integrated with MS Outlook.
    Attachement is not going, but the fle link of the attachement is visible and that too in the Outlook Outbox but the mail is goving without the attachement

    When I am trying to send an email with attachement using JACOB integrated with MS Outlook.
    Attachement is not going, but the fle link of the attachement is visible and that too in the Outlook Outbox but the mail is goving without the attachement

  • Problems to SEND MAIL using WWV_FLOW_MAIL.SEND - APEX_MAIL

    I tried send mail using the code below
    DECLARE
    l_body      CLOB:= EMPTY_CLOB;
    l_body_html CLOB:= EMPTY_CLOB;
    BEGIN
    wwv_flow_api.set_security_group_id;
    l_body :='<html>
    +<head>+
    +<style type="text/css">+
    +body{font-family: Arial, Helvetica, sans-serif;+
                                   +font-size:10pt;+
                                   +margin:30px;+
                                   +background-color:#ffffff;}+
    +span.sig{font-style:italic;+
    font-weight:bold;
    color:#811919;}
    +</style>+
    +</head>+
    +<body>+
    +</html>';+
    l_body_html := '<html>
    +<head>+
    +<style type="text/css">+
    +body{font-family: Arial, Helvetica, sans-serif;+
                                   +font-size:10pt;+
                                   +margin:30px;+
                                   +background-color:#ffffff;}+
    +span.sig{font-style:italic;+
    font-weight:bold;
    color:#811919;}
    +</style>+
    +</head>+
    +<body>+
    +</html>';+
    wwv_flow_mail.send('[email protected]','[email protected]',nvl(l_body,'Texto com erro'),nvl(l_body_html,'erro2'),'K','[email protected]',
    +'[email protected]','[email protected]');+
    wwv_flow_mail.push_queue;
    END;
    +/+
    This code return the message:
    Mail To From Subject CC BCC Created On Created By Error Created
    CHECK$01 [email protected] [email protected] K [email protected] [email protected] 08/23/2010 03:05:00 PM SYS
    ORA-06502: PL/SQL: erro: erro de conversão de caractere em número numérico ou de valor
    Follow my mail settings
    SMTP Host Address : POP.SLE.TERRA.COM.BR
    SMTP Host Port 110
    Administration Email Address [email protected]
    Notification Email Address [email protected]
    what´s wrong ?

    I would try sending just basic text first, then move on to getting your other pieces dynamics. The very last step to me would be the email body.
    Here is an example of a basic text email I use:
    declare
      e_id        NUMBER;
      c_id        NUMBER;
      emp_nm      VARCHAR2(100);
      clrk_id     NUMBER;
      e_clrk      VARCHAR2(47);
      e_org       NUMBER;
      e_sender    VARCHAR2(50);
      e_recip_lst VARCHAR2(255); 
      e_cc        VARCHAR2(100);
      e_bcc       VARCHAR2(100);
      e_subj      VARCHAR2(50);
      e_msg_ln1   VARCHAR2(100);
      e_msg_ln2   VARCHAR2(100);
      e_msg_ln3   VARCHAR2(100);
      e_msg_ln4   VARCHAR2(100);
      e_msg_ln5   VARCHAR2(100);
      e_msg       VARCHAR2(1000);
      CRLF        CHAR(2) := CHR(13) || CHR(11);
      tmp_flag    NUMBER;
    begin
       if :P2_INJURY_FLAG = 1 then
       -- find out if it has changed first so we don't keep sending emails
        select injury_flag, VEH_LOC
          into tmp_flag, e_org
          from APPS.tc
         where tc_id = :P2_TC_ID;
       if :P2_injury_flag <> tmp_flag then
        begin
           select FN_GET_USER(nvl(v('APP_USER'),user))
             into clrk_id 
             from dual;
          select ADMIN_USERNAME
             into e_clrk
            from APPS.APEX_ACCESS_CONTROL
           where ID = clrk_id;
        exception
           when others then null; -- in case we cannot find the user
        end;
        e_id          :=  :P2_EMP_ID;
        c_id          :=  :P2_TC_ID;
        select EMP_FNAME ||' '|| EMP_MNAME ||' '|| EMP_LNAME into emp_nm
          from APPS.EMPLOYEES
         where EMP_ID = e_id;  --
        select RECIPIENTS, CC, BCC
          into e_recip_lst, e_cc, e_bcc
          from APPS.SAFETY_NOTIFICATIONS
         where ORG_ID = e_org;  --
          e_sender    :=  '[email protected]';
          e_subj      :=  'Loss Reported';
          e_msg_ln1   :=  'Employee: ' || emp_nm || ' (' || e_id || ')'  
                          || CRLF;
          e_msg_ln2   :=  'Was reported as sustaining a loss' || CRLF;
          e_msg_ln3   :=  'by ' || e_clrk ||CRLF;
          e_msg_ln4   :=  CRLF;
          e_msg_ln5   :=  'Sent ' || to_char(sysdate,'MONTH DD,YYYY HH:MI AM');
          e_msg       :=  e_msg_ln1 || e_msg_ln2 || e_msg_ln3 || e_msg_ln4 || e_msg_ln5 || CRLF || e_recip_lst;
         utl_mail.send(
           sender => e_sender,
           recipients => e_recip_lst,
           cc => e_cc,
           bcc => e_bcc,
           subject => e_subj,
           message => e_msg);
      end if;
    end if;
    end;

  • Problem in sending the attachment using SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi,
    I have a requirement to send the details of an internal table to External mail as an attachment. I have used fn.module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to do so. I am getting the attachment but the data is stored in only one row when we checked it in SAP outbox. This is irrespective of TXT, XLS etc. I can not check the exact file in my external mail inbox as the connection is not established in dev & Quality systems. This question was raised earlier by other guys and there was no correct answer provided. If any of you encountered this type of problem & got the solution please help.
    Thanks,
    Ashok

    Hi Buddy,
        Hope this piece of code will definately help you out, Its working at my end.
    Thanks,
    Krishna..
    FORM p_send_email .
      FIELD-SYMBOLS: <field> TYPE ANY.
      DATA : BEGIN OF i_dload OCCURS 0 ,
             dload(1000) ,
           END OF i_dload .
      DATA: it_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
              w_object_content LIKE solisti1 OCCURS 1 WITH HEADER LINE.
      DATA: w_doc_data LIKE sodocchgi1 OCCURS 0 WITH HEADER LINE.
      DATA :w_records TYPE zres_records.
      DATA: w_rsnum(10),
            w_bdmng(14),
            w_meins(4).
      DATA: ws_email LIKE adr6-smtp_addr.  "for internal e_mail address
      DATA: ws_email1 LIKE adr6-smtp_addr. "for external e_mail address
    *--Internal table declaration
      DATA: it_objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
      DATA: it_objhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
      DATA: it_objbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
      DATA: it_objtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
      DATA: it_reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
      DATA: doc_chng  LIKE sodocchgi1.
      DATA: tab_lines LIKE sy-tabix.
      DATA: w_longtext(500) TYPE c.
      DATA: v_date(10) TYPE c.
      DATA: text(200)  TYPE c.
      DATA: w_text(50) TYPE c.
    *--Get receipient address
      CLEAR it_reclist.
    *--To send error to internal mail
      ws_email = p_email.
    *--To send error to external mail
      ws_email1 = p_email1.
    *---setting name of file for csv
      CONCATENATE text-003 p_bdoc text-004 INTO w_filename.
      CONDENSE w_filename NO-GAPS.
      IF flag <> 1.
        IF p_email1 IS NOT INITIAL.
    build body of message
          CONCATENATE 'disply message ' ' ' INTO it_objtxt
           SEPARATED BY space.
          APPEND it_objtxt.
          CLEAR it_objtxt.
          it_reclist-receiver = ws_email1.
          it_reclist-rec_type = c_u.
          it_reclist-express  = ' '.
          it_reclist-com_type = 'INT'.
          APPEND it_reclist.
    Set title of object and email
          CLEAR: w_text.
         CONCATENATE 'Greenheck Packing List Data'
                            INTO w_text SEPARATED BY space.
          doc_chng-obj_descr = text-005. "w_text.
          doc_chng-obj_name  = 'Inbound EDI'.
          DESCRIBE TABLE it_objtxt LINES tab_lines.
          READ TABLE it_objtxt INDEX tab_lines.
          doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
    *--Move the Report Name as the Heading line for email file
          CLEAR: w_longtext.
    MOVE: text-012 TO w_longtext.
          w_longtext = 'name of report for testing'.
          it_objbin = w_longtext.
          APPEND it_objbin. CLEAR it_objbin.
    *--Append Blank Lines
          APPEND it_objbin. CLEAR it_objbin.
          APPEND it_objbin. CLEAR it_objbin.
    *User name
          CLEAR text.
          MOVE: 'User:' TO text,
                 sy-uname TO text+6.
          it_objbin = text.
          APPEND it_objbin. CLEAR it_objbin.
    ---appending heading to Internal table of Email
          CLEAR: w_longtext, w_xblnr_1 , w_aubel_1,   w_vemng_1,
                 w_matnr_1,  w_harmdesc_1, w_hc_1, w_cooland1_1,
                 w_brgew_1,  w_tknum_1,   w_vbeln_1,  w_vbeln1_1,
                 w_exidv_1,  w_vhilm_1,   w_pack_no_1,
                 w_brgew1_1, w_laeng_1,   w_breit_1,
                 w_hoehe_1,   w_vol_1.
          w_xblnr_1 = 'Cust PO No.'.
          w_aubel_1 = 'Sal Order'.
          w_vemng_1 = 'Pack Qty'.
          w_matnr_1 = 'Model no.'.
          w_harmdesc_1 = 'Hrm Desc'.
          w_hc_1 = 'Hrm Code'.
          w_cooland1_1 = 'Country of Origin'.
          w_brgew_1 = 'Net Wt.'.
          w_tknum_1 = 'Shipment'.
          w_vbeln_1 = 'Billing Doc'.
          w_vbeln1_1 = 'Delivery'.
          w_exidv_1 = 'Pkg ID'.
          w_vhilm_1 = 'Pkg Desc'.
          w_pack_no_1 = 'Pkg No.'.
          w_brgew1_1 = 'Gross Wt'.
          w_laeng_1 = 'Length'.
          w_breit_1 = 'Width'.
          w_hoehe_1 = 'Height'.
          w_vol_1 = 'Cubic Mtr'.
          CONCATENATE w_xblnr_1  w_aubel_1   w_vemng_1
                      w_matnr_1  w_harmdesc_1 w_hc_1   w_cooland1_1
                      w_brgew_1  w_tknum_1   w_vbeln_1  w_vbeln1_1
                      w_exidv_1  w_vhilm_1   w_pack_no_1
                      w_brgew1_1 w_laeng_1   w_breit_1
                      w_hoehe_1   w_vol_1
          INTO w_longtext SEPARATED BY ','.
          it_objbin = w_longtext.
          APPEND it_objbin. CLEAR it_objbin.
          LOOP AT it_tab.
            DO.
              ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
              IF sy-subrc <> 0.
                EXIT.
              ENDIF.
    Look for Commas in the field value.  If it exists, put quotes around
    value so that the file opens correctly with all the columns aligned
    in Excel.
              SEARCH <field> FOR ',' IN CHARACTER MODE.
    If search for commas was successful.
              IF sy-subrc = 0.
                CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
              ENDIF.
              IF sy-index = 1.
                i_dload-dload = <field>.
                SHIFT: i_dload-dload  LEFT DELETING LEADING space.
              ELSE.
    Put Comma as a separator for values in IT_DLOAD internal table
                SHIFT: i_dload-dload  LEFT DELETING LEADING space.
                CONCATENATE i_dload-dload <field> INTO i_dload-dload
                            SEPARATED BY ',' IN CHARACTER MODE.
              ENDIF.
            ENDDO.
            it_objbin = i_dload-dload.
            APPEND it_objbin. CLEAR it_objbin.
          ENDLOOP.
              flag = 1.
            endif.
        ENDIF.
    ---if to send error file.
        IF p_email IS NOT INITIAL.
    build body of message
          CONCATENATE 'Errors in file ' ' ' INTO it_objtxt
           SEPARATED BY space.
          APPEND it_objtxt.
          CLEAR it_objtxt.
          it_reclist-receiver = ws_email.
          it_reclist-rec_type = c_u.
          it_reclist-express  = ' '.
          it_reclist-com_type = 'INT'.
          APPEND it_reclist.
    Set title of object and email
          CLEAR: w_text.
       CONCATENATE 'Greenheck Packing List Data'
                          INTO w_text SEPARATED BY space.
          doc_chng-obj_descr = text-005.
          doc_chng-obj_name  = 'Inbound EDI'.
          DESCRIBE TABLE it_objtxt LINES tab_lines.
          READ TABLE it_objtxt INDEX tab_lines.
          doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
    *--Move the Report Name as the Heading line for email file
          CLEAR: w_longtext.
    MOVE: text-012 TO w_longtext.
          w_longtext = 'name of report for testing'.
          it_objbin = w_longtext.
          APPEND it_objbin. CLEAR it_objbin.
    *--Append Blank Lines
          APPEND it_objbin. CLEAR it_objbin.
          APPEND it_objbin. CLEAR it_objbin.
    *User name
          CLEAR text.
          MOVE: 'User:' TO text,
                 sy-uname TO text+6.
          it_objbin = text.
          APPEND it_objbin. CLEAR it_objbin.
    ---appending heading to Internal table of Email
          CLEAR: w_longtext, w_xblnr_1 , w_aubel_1,   w_vemng_1,
                 w_matnr_1,  w_harmdesc_1, w_hc_1,  w_cooland1_1,
                 w_brgew_1,  w_tknum_1,   w_vbeln_1,  w_vbeln1_1,
                 w_exidv_1,  w_vhilm_1,   w_pack_no_1,
                 w_brgew1_1, w_laeng_1,   w_breit_1,
                 w_hoehe_1,   w_vol_1, w_error.
          w_xblnr_1 = 'Cust PO No.'.
          w_aubel_1 = 'Sal Order'.
          w_vemng_1 = 'Pack Qty'.
          w_matnr_1 = 'Model no.'.
          w_harmdesc_1 = 'Hrm Desc'.
          w_hc_1 = 'Hrm Code'.
          w_cooland1_1 = 'Counrty of Origin'.
          w_brgew_1 = 'Net Wt.'.
          w_tknum_1 = 'Shipment'.
          w_vbeln_1 = 'Billing doc'.
          w_vbeln1_1 = 'Delivery'.
          w_exidv_1 = 'Pkg ID'.
          w_vhilm_1 = 'Pkg Desc'.
          w_pack_no_1 = 'Pkg No.'.
          w_brgew1_1 = 'Gross Wt'.
          w_laeng_1 = 'Length'.
          w_breit_1 = 'Width'.
          w_hoehe_1 = 'Height'.
          w_vol_1 = 'Cubic Mtr'.
          w_error = 'Error'.
          CONCATENATE w_xblnr_1  w_aubel_1   w_vemng_1
                      w_matnr_1  w_harmdesc_1 w_hc_1  w_cooland1_1
                      w_brgew_1  w_tknum_1   w_vbeln_1  w_vbeln1_1
                      w_exidv_1  w_vhilm_1   w_pack_no_1
                      w_brgew1_1 w_laeng_1   w_breit_1
                      w_hoehe_1   w_vol_1 w_error
          INTO w_longtext SEPARATED BY ','.
          it_objbin = w_longtext.
          APPEND it_objbin. CLEAR it_objbin.
    *--Append the details to Internal table of Email
          LOOP AT it_tab.
            DO.
              ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
              IF sy-subrc <> 0.
                EXIT.
              ENDIF.
    Look for Commas in the field value.  If it exists, put quotes around
    value so that the file opens correctly with all the columns aligned
    in Excel.
              SEARCH <field> FOR ',' IN CHARACTER MODE.
    If search for commas was successful.
              IF sy-subrc = 0.
                CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
              ENDIF.
              IF sy-index = 1.
                i_dload-dload = <field>.
                SHIFT: i_dload-dload  LEFT DELETING LEADING space.
              ELSE.
    Put Comma as a separator for values in IT_DLOAD internal table
                SHIFT: i_dload-dload  LEFT DELETING LEADING space.
                CONCATENATE i_dload-dload <field> INTO i_dload-dload
                            SEPARATED BY ',' IN CHARACTER MODE.
              ENDIF.
            ENDDO.
            it_objbin = i_dload-dload.
            APPEND it_objbin. CLEAR it_objbin.
          ENDLOOP.
           flag = 0.
          endif.
    -Convert to correct format----
      CALL FUNCTION 'SO_RAW_TO_RTF'
        TABLES
          objcont_old = it_objbin
          objcont_new = it_objbin.
    create the control table entry for the main email
      DESCRIBE TABLE it_objtxt LINES tab_lines.
      CLEAR it_objpack-transf_bin.
      it_objpack-head_start = 1.
      it_objpack-head_num   = 0.
      it_objpack-body_start = 1.
      it_objpack-body_num   = tab_lines.
      it_objpack-doc_type   = 'RAW'.
      APPEND it_objpack.
      DESCRIBE TABLE it_objbin LINES tab_lines.
      it_objpack-head_start = 1.
      it_objpack-head_num   = 0.
      it_objpack-body_start = 1.
      it_objpack-body_num   = tab_lines.
      it_objpack-transf_bin = c_x.
      it_objpack-doc_type   = 'CSV'.
      it_objpack-obj_descr  = w_filename. "'billing doc no.csv'.
      it_objpack-obj_name   = 'Billing Doc'.
      it_objpack-doc_size   = tab_lines * 255.
      APPEND it_objpack.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_chng
         PUT_IN_OUTBOX              = c_x
          commit_work                = c_x
        TABLES
          packing_list               = it_objpack
         object_header              = it_objhead
          contents_bin               = it_objbin
          contents_txt               = it_objtxt
          receivers                  = it_reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      IF sy-subrc <> 0.
        WRITE: / 'failure in sending mail'.
      ELSE.
         if flag = 0.
           MESSAGE s999(pp) WITH text-007.
         endif.
         if flag = 1.
           MESSAGE s999(pp) WITH text-006.
         endif.
       WRITE: / 'success in sending mail'.
      ENDIF.
        ENDFORM.                    " p_send_email

  • Problem with attachment using SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi,
    I'm using function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send emails from SAP (to Outlook - but the problem can already be observed when checking the email attachment in transaction SOST) with attachments.
    My attachment is a tab delimited file (so that I can open with MS Excel) with a line size of approx. 1600 characters. I mean, concatenating all fields of the output table into a 1600 character field, separated by tabstops (cl_abap_char_utilities=>horizontal_tab)
    I am using function module SCMS_STRING_TO_FTEXT to convert the internal table that I want to send to the line size as accepted by function module SO_NEW_DOCUMENT_ATT_SEND_API1, tables parameter contents_bin. Due to function module SCMS_STRING_TO_FTEXT this happens line by line, using a string variable. I make sure to remove any exess blanks that appear in the process due to not completey filled character fields. And for all rows bar the first the string is prefixed with (cl_abap_char_utilities=>cr_lf). I believe that's required so that SAP knows to put the lines back together. So far so good.
    When checking the email's attachment via SOST (and the same happens in Outlook) there are extra blanks in certain fields. Like:
    Annual Base
    92,928.         00
    or
    Email
    First L ast
    In debugging it appears that these excess spaces (sometimes 1, sometimes several) appear where the 1600 character data line is split into the 255 character pieces in 'contents_bin'. But then it happens quite randomly and cannot be observed in all data rows.
    Is there a better way of splitting my internal table into 255 character chunks so that what is one field will never get split up into two rows. For the above example, the two fields would show like this in contents_bin
    ....  92,928.        
    00
    and
    First_L
    ast
    Or where else lies the problem?
    Thanks in advance!
    Philipp

    Ron,
    Thank you for the suggestion. Just tried but issue remains exactly the same. The function module you have suggested builds the table in the same way.
    But, after a few more rounds of debugging and scratching my head it occured to me that my problem is self inflicted. I was using the condense statement in an attempt to get rid of the trailing blanks at the end of a row causing the last column to be filled with lots of spaces at the end. But it wasn't working anyway and I have since inserted a dummy column at the end to take all those trailing blanks. What this condense statement did though was creating trailing blanks in some of those rows with 255 characters fixed length and those trailing blanks then showed up as additional blanks in some columns in the attachment that the emailing function module created by putting those lines back to it's original length of close to 1600 characters.
    Problem solved!
    Regards,
    Philipp

  • Unique Problem: Returning SOAP+ Attachment using a class based webservice

    Hi everyone,
    Im trying to return a Soap+ attachment response back using the following:
    attachDoc(byte[] bdoc, String sTransactionNumber,
                   String sRequestedType)
    Where byte[] is the attachment and the 2 string parameters are soap message contents.
    The attachment is attached successfully to the message and i can send a response back to the clients console using :
    message.writeTo(System.out);
    My problem is that i dont know how to return this soapmessage+attachment back to the client.
    Ive tried using the return type of the method as :
    public SOAPMessage attachDoc(byte[] bdoc, String sTransactionNumber,
                   String sRequestedType)
    but i cant return a SOAPMessage return type in axis.
    Does anyone have any clues how i should sort this out so that the client gets the SOAPMessage and attachment when the method is called ?
    Please help :S
    Thanks,

    I dunno if this is what you asked for....
    Hope this helps a bit
    You may want to check this link out
    http://www-unix.globus.org/mail_archive/discuss/2007/02/msg00037.html
    MessageContext msgContext = MessageContext.getCurrentContext();
    File file = new File("filename.txt");
    org.apache.axis.attachments.AttachmentPart replyPart=
    new org.apache.axis.attachments.AttachmentPart(new DataHandler(new
    FileDataSource(file)));
    Message rspMsg= msgContext.getResponseMessage();
    rspMsg.addAttachmentPart(replyPart);
    so ur basically adding the file to the reply message.
    The link i gave has a better description, it has the entire process of sending file to server and downloading file from server codes.

  • Multiple attachment using SO_NEW_DOCUMENT_ATT_SEND_API1

    HI geeks,
              Can anyone pls tell me how to attach multiple files using function module SO_NEW_DOCUMENT_ATT_SEND_API1.
              I have seen example of multiple attachments using same file type.I mean 1 or more files are same type like PDF or Excel.
              But my requirement is i have to send multiple attachment,1 file as PDF and other three excel file.
              Can anyone pls let me know,if anyone done this already,
    Thanks in advance
    Srini.

    Hi Srinivasn,
    Please see the below code u need to follow.  In the object pack table u might specified the number of lines per each attachement.  At the same time u need to specify the document type as  PDF  or XLS.  Please see the below code which is wrote for two attachments as xls.  In your case one attachment should be PDF.  This can be specified in the field
    LT_OBJPACK-DOC_TYPE = 'PDF'.
    IF NOT LT_ATT_TAB[] IS INITIAL AND
        NOT GV_ERR_REC IS INITIAL.        
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_SUC_REC.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = 1.
        LT_OBJPACK-HEAD_NUM = 0.
        LT_OBJPACK-BODY_START = 1.
        LT_OBJPACK-BODY_NUM = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE = LC_XLS.
        LT_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
        LT_OBJPACK-OBJ_DESCR = LV_ATTACH_NAME2(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    File2 attachment for processed records.
      IF NOT LT_ATT_TAB[] IS INITIAL AND
         NOT GV_SUC_REC IS INITIAL.
        CLEAR LT_OBJPACK.
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_ERR_REC.
        GV_ERR_REC = GV_ERR_REC + 1.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = GV_ERR_REC.
        LT_OBJPACK-HEAD_NUM   = 0.
        LT_OBJPACK-BODY_START = GV_ERR_REC.
        LT_OBJPACK-BODY_NUM   = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE   = LC_XLS.
        LT_OBJPACK-OBJ_NAME   = 'ATTACHMENT'(009).
        LT_OBJPACK-OBJ_DESCR  = LV_ATTACH_NAME(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    Thanks
    IF NOT LT_ATT_TAB[] IS INITIAL AND
        NOT GV_ERR_REC IS INITIAL.        
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_SUC_REC.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = 1.
        LT_OBJPACK-HEAD_NUM = 0.
        LT_OBJPACK-BODY_START = 1.
        LT_OBJPACK-BODY_NUM = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE = LC_XLS.
        LT_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
        LT_OBJPACK-OBJ_DESCR = LV_ATTACH_NAME2(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    File2 attachment for processed records.
      IF NOT LT_ATT_TAB[] IS INITIAL AND
         NOT GV_SUC_REC IS INITIAL.
        CLEAR LT_OBJPACK.
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_ERR_REC.
        GV_ERR_REC = GV_ERR_REC + 1.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = GV_ERR_REC.
        LT_OBJPACK-HEAD_NUM   = 0.
        LT_OBJPACK-BODY_START = GV_ERR_REC.
        LT_OBJPACK-BODY_NUM   = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE   = LC_XLS.
        LT_OBJPACK-OBJ_NAME   = 'ATTACHMENT'(009).
        LT_OBJPACK-OBJ_DESCR  = LV_ATTACH_NAME(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    Venkat

  • Mail Send Functionality using SO_NEW_DOCUMENT_ATT_SEND_API1

    hi,
    i m using Fn Module "SO_NEW_DOCUMENT_ATT_SEND_API1" to send email with attachment.
    I have written  a program which will fetch data in excel format . this excel should be sent as attachment to specified receiver. however i m having difficulties adding attachment to function module.
    I specified under parameter "contents_bin" but its giving some error message related wth structure.
    I chkd SDN and wasnt able to find any resolution yet.
    Any suggestion or idea which can be useful on this.
    Thanks.

    REPORT  zsendemail                    .
    PARAMETERS: psubject(40) type c default  'Hello',
                p_email(40)   type c default 'write email address' .
    data:   it_packing_list like sopcklsti1 occurs 0 with header line,
            it_contents like solisti1 occurs 0 with header line,
            it_receivers like somlreci1 occurs 0 with header line,
            it_attachment like solisti1 occurs 0 with header line,
            gd_cnt type i,
            gd_sent_all(1) type c,
            gd_doc_data like sodocchgi1,
            gd_error type sy-subrc.
    data:   it_message type standard table of SOLISTI1 initial size 0
                    with header line.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Perform populate_message_table.
    *Send email message, although is not sent from SAP until mail send
    *program has been executed(rsconn01)
    PERFORM send_email_message.
    *Instructs mail send program for SAPCONNECT to send email(rsconn01)
    perform initiate_mail_execute_program.
    *&      Form  POPULATE_MESSAGE_TABLE
          Adds text to email text table
    form populate_message_table.
      Append 'Email line 1' to it_message.
      Append 'Email line 2' to it_message.
      Append 'Email line 3' to it_message.
      Append 'Email line 4' to it_message.
    endform.                    " POPULATE_MESSAGE_TABLE
    *&      Form  SEND_EMAIL_MESSAGE
          Send email message
    form send_email_message.
    Fill the document data.
      gd_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      gd_doc_data-obj_langu = sy-langu.
      gd_doc_data-obj_name  = 'SAPRPT'.
      gd_doc_data-obj_descr = psubject.
      gd_doc_data-sensitivty = 'F'.
    Describe the body of the message
      clear it_packing_list.
      refresh it_packing_list.
      it_packing_list-transf_bin = space.
      it_packing_list-head_start = 1.
      it_packing_list-head_num = 0.
      it_packing_list-body_start = 1.
      describe table it_message lines it_packing_list-body_num.
      it_packing_list-doc_type = 'RAW'.
      append it_packing_list.
    Add the recipients email address
      clear it_receivers.
      refresh it_receivers.
      it_receivers-receiver = p_email.
      it_receivers-rec_type = 'U'.
      it_receivers-com_type = 'INT'.
      it_receivers-notif_del = 'X'.
      it_receivers-notif_ndel = 'X'.
      append it_receivers.
    Call the FM to post the message to SAPMAIL
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           exporting
                document_data              = gd_doc_data
                put_in_outbox              = 'X'
           importing
                sent_to_all                = gd_sent_all
           tables
                packing_list               = it_packing_list
                contents_txt               = it_message
                receivers                  = it_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.
    Store function module return code
      gd_error = sy-subrc.
    Get it_receivers return code
      loop at it_receivers.
      endloop.
    endform.                    " SEND_EMAIL_MESSAGE
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
          Instructs mail send program for SAPCONNECT to send email.
    form initiate_mail_execute_program.
      wait up to 2 seconds.
      if gd_error eq 0.
          submit rsconn01 with mode = 'INT'
                        with output = 'X'
                        and return.
      endif.
    endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

  • Problems in Sending mails using java mail

    hi all,
    heres my piece of code-
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;
    public class SendEmail
         public static void main(String[] args)
    System.out.println(args.length);
              if (args.length != 6)
                   System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
                   System.exit(1);System.out.println("jj"+args.length);
         SendEmail m=new SendEmail();
         m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
    public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
         boolean debug = false; // change to get more information
    String msgText2 = "multipart message";
    boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
    // set the host
    Properties props = new Properties();
    props.put("mail.smtp.host",smtphost);
         props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.sendpartial", "true");
    Authenticator loAuthenticator = new SMTPAuthenticator();
    System.out.println("f");
    // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, loAuthenticator );
    session.setDebug(debug);
    System.out.println("ff");
    //System.out.println( loAuthenticator);
    try
    // create a message
    Message msg = new MimeMessage(session);
    // set the from
    InternetAddress from = new InternetAddress(emailfrom);
    msg.setFrom(from);
    InternetAddress[] address =
    new InternetAddress(emailto)
    //InternetAddress ad=new InternetAddress(session);
    //System.out.println(ad.getLocalAddress());
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(msgSubject);
    if(!sendmultipart)
    // send a plain text message
    msg.setContent(msgText, "text/plain");
    else
    // send a multipart message// create and fill the first message part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setContent(msgText, "text/plain");
    // create and fill the second message part
    MimeBodyPart mbp2 = new MimeBodyPart();
    mbp2.setContent(msgText2, "text/plain");
    // create the Multipart and its parts to it
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    // add the Multipart to the message
    msg.setContent(mp);
    Transport transport = session.getTransport("smtp");
         transport.connect(smtphost,"[email protected]","xyz");
    msg.saveChanges();
              //transport.sendMessage(msg,msg.getAllRecipients());
    transport.sendMessage(msg,msg.getAllRecipients());
    transport.close();     
    catch(MessagingException mex)
    mex.printStackTrace();
    return "Email sent to " + emailto;
    class SMTPAuthenticator extends Authenticator
    public PasswordAuthentication getPasswordAuthentication()
    String username = "[email protected]";
    String password = "xyz";
    return new PasswordAuthentication(username, password);
    i get the following errors-
    SmtpSendFailedException:550 Invalid Recipient
    Sometimes the mail gets send but sometimes it doesnt (while sending it to yahoo)..
    i guess there is some firewall problem..
    can somebody help me please.
    thanks

    Hello. I don't know if this will help you much but just reading the posts there might be something wrong with the information that is being sent to your SMTP host. You might make sure that the string that you are sending doesn't have extra characters attached to it or that a timeout is not occuring during the transfer of your username/password information. Sometimes the '@' gets translated into something else.
    A 550 error usually indicates that the mail server didn't recived a valid user on the system, this came into play I believe when people start abusing SMTP to SPAM a server using everything under the sun...so filters were put in place i.e. If you are not a Qualified Domain Name registered mailserver and someone has a filter in place your message will go kersplat because forwarding is no longer being allowed. Yopu might try a diffrent tactic.
    1. you might trim your strings.
    2. build strings in a connect method so that its a bit less amateur code.
    public void connect() {
            // Display connect dialog.
            ConnectDialog dialog = new ConnectDialog(this);
            dialog.show();
            // Build connection URL from connect dialog settings.
            StringBuffer connectionUrl = new StringBuffer();
            connectionUrl.append(dialog.getType() + "://");
            connectionUrl.append(dialog.getUsername() + ":");
            connectionUrl.append(dialog.getPassword() + "@");
            connectionUrl.append(dialog.getServer() + "/");3. Make absolutely certain that the SMTP server you are sending from is registered and qualified in your code. Meaning you can't use a bogus MTA(mail trasport agent) or you get bounced.
       private void sendMessage(int type, Message message) {
            // Display message dialog to get message values.
            MessageDialog dialog;
            try {
                dialog = new MessageDialog(this, type, message);
                if (!dialog.display()) {
                    // Return if dialog was cancelled.
                    return;
            } catch (Exception e) {
                showError("Unable to send message.", false);
                return;
            try {
                // Create a new message with values from dialog.
                Message newMessage = new MimeMessage(session);
                newMessage.setFrom(new InternetAddress(dialog.getFrom()));
                newMessage.setRecipient(Message.RecipientType.TO,
                        new InternetAddress(dialog.getTo()));
                newMessage.setSubject(dialog.getSubject());
                newMessage.setSentDate(new Date());
                newMessage.setText(dialog.getContent());
                // Send new message.
                Transport.send(newMessage);
            } catch (Exception e) {
                showError("Unable to send message.", false);
        }Lastly, if you are writing a SPAM client, you should go to your dos prompt and type format c: (j/k)
    now the disclaimer. The code published is not mine it was a piece of an example that I got from a brillient book by Herbert Schildt and James Holmes who I would love to be able to chat with since the work they do is absolutely perfect. You might check it out from your Local Library the ISBN is 0-07-222971-3 they have a whole section just on JavaMail.
    Well hope that gets you started in the right direction, I would read the ISO standards published for SMTP, you might get a better grip on the error codes that are bound to come up.

  • Problem in Sending attachement title in Workflow

    Hi,
    We have created a workflow.It pick up the data from the application server and is send as attachement in workitem using oject type SOFM..The problem Know is  we want to send the attachement another set of user through mail.We are able to send the attachement in mail but it does not give TItle of attachments in mail.
    So, how can I get the Title of the attachment in the mail.......
    if u have any solution please reply to this thread...
    thanks in advance............

    How are you sending it in mail; manually or using a program? If you are using a program you must have forgotten to set the title, which is part of the structure you have to fill for every attachment.

  • Powershell scripting to send emails based on events in event viewer **PROBLEM IS SENDING attachment of log**

    $emailFrom = "[email protected]"
    $emailTo = "[email protected]"
    $subject = "$env:COMPUTERNAME : A VM was successfully migrated."
    $body = "$env:COMPUTERNAME : A VM was successfully migrated."
    $smtpServer = "smtp.domain.com"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($emailFrom, $emailTo, $subject, $body)
    this is a template of a ps1 script i wrote. This will send the above email based on a specific event ID for the microsoft failover cluster / operational, say ID 5143 for example. My question is how do i include in that script to also include a copy of the
    log for that event ID in the body of the email ?

    You problem with this code is that the SMTPClient send method does not handle attachements.
    Instead, try creating the message, using the system.net.mail.mailmessage class to create the message.Then create a mail attachment. Finally, add the attachment to the message. This allows you to craate an attachment, then use the SMTPServer object to send
    that mail.
    The code should look something like this:
    $To      = "[email protected]"
    $From    = "[email protected]"
    $Subject = "Using the .NET SMTP client."
    $Body    = "Using this .NET feature, you can send an e-mail message from an application very easily."
    # Create mail message
    $Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
    $AttchmentText = get-content C:\foo\aaaaaaa.txt  # or whatever
    # Now create Attachement content type
    $ct = new-object System.Net.Mime.Contenttype
    $ct.name = 'text/plain'
    # Now create an attachment of that type
    $attachment = [System.Net.Mail.Attachment]::CreateAttachmentFromString($attchmenttext,$ct)
    # Next add Attachment to the message
    $message.Attachments.Add($attachment)
    # and now create smtp server
    $smtpServer = "COOKHAM8"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($message)
    I tested this script on my system and it works. You may need to play around a bit with the attachment, in terms of content type, etc.
    Thomas Lee <[email protected]>

Maybe you are looking for

  • 2 iTunes folders on one computer, 1 iPod - does it work?

    This part seems to work: putting one iTunes folder into the users>music folder at a time, with the other iTunes folder (containing its own iTunes Music folder and library) into a folder located elsewhere on the computer. If I just switch the entire i

  • Urgent- How to Default Current Months First Date in a Dashboard Prompt

    We have requirement that whenever our user clicks on a dashboard it should show the report associated with the dashboard defaulted to MTD. For example if the user is running the dashboard on 16th Jan then the report associated with dashboard by defau

  • Keyboard Shortcut for adding clip to queue when importing from P2 card

    Does anyone know what the keyboard shortcut is for adding a clip to the queue when importing from a P2 card? Thanks! G5   Mac OS X (10.4.8)  

  • What is Excel doing?

    Hello, We have a simple cube prototype with one fact table and two dimensions (on SQL Server 2008 R2) When I place two fields, one from each dimension, on the Excel pivot table designer, Excel shows data. In particular, it shows over 6000 rows for th

  • Purchase on behalf of another co .

    PLease let me know the [process for a procure to pay proceedure for a co code that is purchasing on behalf of another co .. Say there are 2 companies A  and B . A is procuring stationary on behalf of B // What are the enteries that will be created af