Send HTML as attachment in email in Stored Procedure

Hi Guys,
I am writing a stored procedure to send HTML attachment. Below is my code but no html attachment sent in mail. Kindly advise.
USE [CarsemERP]
GO
/****** Object: StoredProcedure [dbo].[DBA_CarsemERP_SQLBlocks] Script Date: 04/01/2015 15:14:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <THARMENDRAN>
-- Create date: <2014FEB21>
-- Description: TO CHECK ANY LOCKS MORE THN 20 SEC IN SQL SERVER
-- =============================================
ALTER PROCEDURE [dbo].[DBA_CarsemERP_SQLBlocks]
AS
BEGIN
DECLARE @iCnt As Int
DECLARE @ICnt2 As Int
DECLARE @SendEmail AS VARCHAR(3)
DECLARE @Temp_DetailReq1 TABLE (
idx smallint Primary Key IDENTITY(1,1),
DBName varchar(30), RequestId Int, BlockingId Int, BlockedObjectName varchar(30),LockType varchar(30), RequestingText varchar(max), BlockingText varchar(max),
LoginName varchar (30), HostName varchar (30))
DECLARE @Temp_DetailReq2 TABLE (
idx smallint Primary Key IDENTITY(1,1),
DBName varchar(30), RequestId Int, BlockingId Int, BlockedObjectName varchar(30),LockType varchar(30), RequestingText varchar(max), BlockingText varchar(max),
LoginName varchar (30), HostName varchar (30))
SET @SendEmail = 'NO'
SELECT @iCnt= COUNT(*) FROM DBA_SQLBlocksViewTharmen
IF @iCnt > 0
BEGIN
Insert Into @Temp_DetailReq1
Select DBName, request_session_id, blocking_session_id, BlockedObjectName,resource_type, RequestingText, BlockingTest, LoginName, HostName From DBA_SQLBlocksViewTharmen
END
WAITFOR DELAY '00:00:20'
select @iCnt2= COUNT(*) FROM DBA_SQLBlocksViewTharmen
IF @iCnt2 > 0
BEGIN
DECLARE @columnHeaders NVARCHAR(MAX)
DECLARE @tableHTML NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
Insert Into @Temp_DetailReq2
Select DBName, request_session_id, blocking_session_id, BlockedObjectName,resource_type, RequestingText, BlockingTest, LoginName, HostName From DBA_SQLBlocksViewTharmen
SET @SendEmail = 'YES'
BEGIN
SET @columnHeaders = 'DBName</th><th>RequestId</th><th>BlockingId</th><th>BlockedObjectName</th><th>LockType</th><th>RequestingText</th><th>BlockingText</th><th>LoginName</th><th>HostName'
set @tableHTML =
'<div><b>There is blocking in VERPSVR02-02.</b></div><br>' + -- This is the bold text at the top of your email
'<table border="0" cellpadding="5"><font face="Calibri" size=2>' +
'<tr><th>' + @columnHeaders + '</th></tr>' +
convert(nvarchar(max),
select td = [DBName], '', -- Here we put the column names
td = [RequestId], '',
td = [BlockingId], '',
td = [BlockedObjectName], '',
td = [LockType], '',
td = [RequestingText], '',
td = [BlockingText], '',
td = [LoginName], '',
td = [HostName], '' -- Here we put the column names
from @Temp_DetailReq2
for xml path('tr'), type)) +'</font></table>'
END
END
IF @SendEmail = 'YES'
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyDBMailProfileName',
@recipients = '[email protected]',
@body = 'Please refer the attachment' ,
@body_format = 'HTML',
@subject = 'Alert! Blocking On ERPSVR02-02 Live Server',
@file_attachments = @tableHTML,
@importance = 'High';
END
END

Hi Guys,
I need help on how to generated HTML as attachment to email. I have write below stored procedure but the html did not send as attachment. Kindly guide me on how to save the generated HTML as a file and send it as attachment.
USE [CarsemERP]
GO
/****** Object: StoredProcedure [dbo].[DBA_CarsemERP_SQLBlocks] Script Date: 04/01/2015 15:14:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <THARMENDRAN>
-- Create date: <2014FEB21>
-- Description: TO CHECK ANY LOCKS MORE THN 20 SEC IN SQL SERVER
-- =============================================
ALTER PROCEDURE [dbo].[DBA_CarsemERP_SQLBlocks]
AS
BEGIN
DECLARE @iCnt As Int
DECLARE @ICnt2 As Int
DECLARE @SendEmail AS VARCHAR(3)
DECLARE @Temp_DetailReq1 TABLE (
idx smallint Primary Key IDENTITY(1,1),
DBName varchar(30), RequestId Int, BlockingId Int, BlockedObjectName varchar(30),LockType varchar(30), RequestingText varchar(max), BlockingText varchar(max),
LoginName varchar (30), HostName varchar (30))
DECLARE @Temp_DetailReq2 TABLE (
idx smallint Primary Key IDENTITY(1,1),
DBName varchar(30), RequestId Int, BlockingId Int, BlockedObjectName varchar(30),LockType varchar(30), RequestingText varchar(max), BlockingText varchar(max),
LoginName varchar (30), HostName varchar (30))
SET @SendEmail = 'NO'
SELECT @iCnt= COUNT(*) FROM DBA_SQLBlocksViewTharmen
IF @iCnt > 0
BEGIN
Insert Into @Temp_DetailReq1
Select DBName, request_session_id, blocking_session_id, BlockedObjectName,resource_type, RequestingText, BlockingTest, LoginName, HostName From DBA_SQLBlocksViewTharmen
END
WAITFOR DELAY '00:00:20'
select @iCnt2= COUNT(*) FROM DBA_SQLBlocksViewTharmen
IF @iCnt2 > 0
BEGIN
DECLARE @columnHeaders NVARCHAR(MAX)
DECLARE @tableHTML NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
Insert Into @Temp_DetailReq2
Select DBName, request_session_id, blocking_session_id, BlockedObjectName,resource_type, RequestingText, BlockingTest, LoginName, HostName From DBA_SQLBlocksViewTharmen
SET @SendEmail = 'YES'
BEGIN
SET @columnHeaders = 'DBName</th><th>RequestId</th><th>BlockingId</th><th>BlockedObjectName</th><th>LockType</th><th>RequestingText</th><th>BlockingText</th><th>LoginName</th><th>HostName'
set @tableHTML =
'<div><b>There is blocking in VERPSVR02-02.</b></div><br>' + -- This is the bold text at the top of your email
'<table border="0" cellpadding="5"><font face="Calibri" size=2>' +
'<tr><th>' + @columnHeaders + '</th></tr>' +
convert(nvarchar(max),
select td = [DBName], '', -- Here we put the column names
td = [RequestId], '',
td = [BlockingId], '',
td = [BlockedObjectName], '',
td = [LockType], '',
td = [RequestingText], '',
td = [BlockingText], '',
td = [LoginName], '',
td = [HostName], '' -- Here we put the column names
from @Temp_DetailReq2
for xml path('tr'), type)) +'</font></table>'
END
END
IF @SendEmail = 'YES'
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MyDBMailProfileName',
@recipients = '[email protected]',
@body = 'Please refer the attachment' ,
@body_format = 'HTML',
@subject = 'Alert! Blocking On ERPSVR02-02 Live Server',
@file_attachments = @tableHTML,
@importance = 'High';
END
END

Similar Messages

  • Sending a binary attachment via email, looking for a more clean way

    Hi experts.
    I finally managed to send a binary attachment via email. Why "finally"? Never done before!
    Also I got to manage the "not standard" .SAP file extension, because the attachment is a transaction link.
    So let me explain how i did it:
    take SO_NEW_DOCUMENT_ATT_SEND_API1, filling following input data:
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = st_docdata
          commit_work                = 'X'
        TABLES
          packing_list               = lt_packlist
          contents_hex               = lt_hex
          contents_txt               = lt_content
          receivers                  = lt_recv
        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.
    But how to fill lt_hex? Well I did not found a way to transfer text data into raw data structure (lt_hex is type SOLIX).
    So, here is the trick:
    fill another table, lt_bin type SOLISTI1, with attachment content (text data);
    dump lt_bin content to a file on application server, having care to specify TEXT MODE and UTF-8 encoding;
    now reopen the same file in BINARY MODE and transfer content to lt_hex.
    Why I did not use parameter
    content_bin
    ? Because SAP ECC 6 is unicode enabled (I think UTF-16) and file has got to be UTF-8 or ASCII. Also, packing_list for attachment must specify binary tranfer mode. And doing so each UTF-16 character (2 bytes) is split into 2 characters (1 char + 1 NUL byte). Attachment is now unusable.
    What is the question? Here it is: how to fill lt_hex data directly from text (UTF-16) data, avoiding conversion errors?
    Thank you in advance.

    Hi Chhayank,
    the problem is not the exported xls. If you have a look inside with Notepad or something like that, you will see that your leading zeros are exported correct.Excel-settings occurs this problem, it is all about how to open the document. If you use the import-assistant you will have no problems because there are options available how to handle the different columns.
    Another solution might be to get familiar with ABAP2XLS-Project. I got in my mind, that there is a method implemented, that will help you solving this problem. But that is not a five minute job
    ~Florian

  • Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Hi Chhayank,
    the problem is not the exported xls. If you have a look inside with Notepad or something like that, you will see that your leading zeros are exported correct.Excel-settings occurs this problem, it is all about how to open the document. If you use the import-assistant you will have no problems because there are options available how to handle the different columns.
    Another solution might be to get familiar with ABAP2XLS-Project. I got in my mind, that there is a method implemented, that will help you solving this problem. But that is not a five minute job
    ~Florian

  • Send  XML as attachment in Email activity

    Hi
    My requirement is to send XML as an attachment through email .
    In the attachment if i select the MIME type as "XML" then no email notification is sent,
    but if i select the MIME type as "text/html" , then attachement is sent through email , but attachment is in different format( with no content inside attachment) .
    Can anyone help me on this .

    have you tried the example on this page : http://java.net/projects/oraclesoasuite11g/pages/Notification

  • How to send HTML page via an email

    Hi..
    I wanna send HTML page with images via an email, it should not go as an attachment.
    Is there any Tool or Software available to send HTML Pages via email.
    i just wanna send my advertisement as a HTML page via email
    So plz. help me out

    Java Message Service (JMS) For more info u can visite http://java.sun.com/products/jms/tutorial/
    It is usefull only when u r using some Application servers like WebLogic, WebSpeher, or JBoss
    Bye

  • How to send file as attachment in Email in Oracle UCM

    Hi All,
    I have created a simple html form which executes my custom service( internally calls java method) to send a email "forms data" to the user. I need to send file as attchment in email so how i can do it in oracle ucm.Currently i am using intradoc api.I am using a jquery plugin for sending forms data including uploaded file.
    function which i am using in java for sending emails:-
    InternetFunctions.sendMailTo(emailStr, "MyMail", subject, this.m_service);
    I have set method="post" and enctype="multipart/form-data" in the form
    So plz help to provide a solution to send a file as attchment in email
    Thanks,
    user9018217

    From what I remember, there isn't an "out of the box" solution since InternetFunctions only provides some basic email functions (try decompiling the class to see what's available).
    Here's the link for the original Stellent 10gR3 sample components: http://www.oracle.com/technetwork/middleware/content-management/index-092832.html. Take a look at the AcmeMail component within the HowTo Components sample. It shows how to create a custom idcservice that sends basic emails. You can use that as a baseline for creating your own email service and then use something like JavaMail to implement attachments. That's what I did.
    Good luck, and please award points as necessary.

  • Sending Excel as attachment in Email (Unicode)

    Hi,
    I'm using SO_NEW_DOCUMENT_ATT_SEND_API1 FM to send excel attachments as emails to external addresses.
    However, this the SAP upgrade to ECC6.0 from R/3 4.6B
    then I cannot open BIG5 char excel, who does know how to sending Unicode excel as attachment in email.
    the Excel can show Chinese , BIG5 code ,Japanese ,Korea .
    OR which new funciton module in ECC6.0 like SO_NEW_DOCUMENT_ATT_SEND_API1 FM .
    Regards,
    Hank

    Hey,
    try this one.
        lv_string = str_data1.
          cl_bcs_convert=>string_to_solix(
            EXPORTING
              iv_string   = lv_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
          iv_add_bom  = 'X'     "for other doc types
            IMPORTING
              et_solix  = binary_content
              ev_size   = size ).
        CATCH cx_bcs.
          MESSAGE e445(so).
      ENDTRY.
            send_request = cl_bcs=>create_persistent( ).
    Now  create document object from internal table with text
    document = cl_document_bcs=>create_document(
              i_type    = 'RAW'
              i_text    = main_text
              i_subject = l_var ).     
           document->add_attachment(
              i_attachment_type    = 'xls'                               i_attachment_subject = ' Details'                      i_attachment_size    = size
              i_att_content_hex    = binary_content ).
        add document object to send request
            send_request->set_document( document ).
        --------- add recipient (e-mail address) -----------------------
        create recipient object
            recipient = cl_cam_address_bcs=>create_internet_address( abc at abc.com).
           recipient = cl_cam_address_bcs=>create_internet_address( 'abc at abc.com' ).
        add recipient object to send request
            send_request->add_recipient( recipient ).
            sent_to_all = send_request->send( i_with_error_screen = 'X' ).
            COMMIT WORK.
    This will definitely work .if any doubts aask me.
    Neeraj

  • Not Able to send pdf as attachment through email

    Hi,
    I am trying to send the generated pdf as attachment throught email and for the same i am referring to this blog
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417100)ID1409662650DB01562818410448928630End?blog=/pub/wlg/8551
    but when i am trying to send the mail using the method given in this blog , i am getting this error
    com.sap.tc.adobe.pdfobject.core.PDFObjectRuntimeException: Processing exception during a "MergeData" operation. Request start time: Fri Dec 11 18:05:24 IST 2009 com.adobe.ProcessingException: PDF is not interactive. Data can only be imported into interactive forms. Exception Stack Trace: com.adobe.ProcessingException: PDF is not interactive
    and at the backend i am getting the error as
    #com.sun.mail.smtp.SMTPSendFailedException: 501 Bad address syntax
    Can any one please help me out with a solution ?? Any suggestions are welcomed
    Thanks a lot in advance

    Hi,
    Thanks for your reply , but i cannot set the enabled property of the form as true as we are not using the licensed version of the live cycle designer . But if i try the example step by step then even by setting the enabled property as false , the pdf is generated and sent through the email and when i am trying to do the same thing in one of my applications its not working . The pdf is generated but as soon as i click on the button send mail the above told error is displayed .
    There needs to be some other explaination for the error

  • Sending large amounts of text to a stored procedure

    All,
    I have created an email application using stored procedures that
    sends email from the database.
    I then created a portal form on top of the stored procedure so
    that I may do my data entry. My form takes 2
    parameters: "subject" and "message". The "To:" list is
    generated dynamically by the database.
    For my "message" data entry, I have created a text area which I
    will paste my email text (html format) into.
    When I attempt to submit my email, I am getting the following
    errors:
    ORA-06502: PL/SQL: numeric or value error: Bulk bind: Error in
    define
    ORA-06502: PL/SQL: numeric or value error: character string
    buffer too small (WWV-11230)
    I know that it is NOT a problem with the HTML text as I have
    tested this.
    Does anyone have any ideas what it may be?
    Thanks,
    Jon.

    John,
    Portal forms process data using varchar fields, I understood
    there to be a limit, well below that of the 32767 limit of the
    varchar because of with it does with it.
    How close is your data to this limit?

  • How do you send a date from java to a stored procedure

    Oracle 8.0.5
    using thin drivers
    I'm trying to pass a date to a stored procedure. Does anybody
    have an example of how to do this.
    I want to send a month-day-year 01/01/1999 to oracle to be
    inserted into the table. what should the java code look like?
    and what should the (in) line look like in oracle.
    Thanks
    Kirk
    null

    Wow. You got me there.  All of the pdfs that i have, when i tap that icon, open a drop down window with the choices of e mail or print.  I wonder if the particular pdf you are working on is somehow protected?  Try a different pdf and see if the box recats the same way.   You might also do a full shut down and just try again.  Make sure there is not an old instance of i books, or some other pdf editor sitting in the task bar, by doblue clicking the home button, and shutting down any open apps.

  • Sending '?' in XML tag to Oracle Stored Procedure

    I have a situation that I cannot find the answer to why it is happening.
    I am sending an XML data type to an oracle stored procedure. In one of the fields, I need to allow the '?' character to be sent.
    <ADDITIONALINFO>This is where I want ? to be</ADDITIONALINFO>
    When I send the info to the stored procedure I get the following error: ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing
    LPX-00216: invalid character 191 (0xBF)Error at line 19
    What I do not understand is that the character (0xBF) is the inverted question mark �
    I have been able to get around the issue by changing the question mark to &#63; which is the decimal format for the question mark and the query works.
    ie: <ADDITIONALINFO>This is where I want &#63 to be</ADDITIONALINFO>
    Is there another delimiter that is needed for '?' like what is needed to print the & in & fashion?
    Any insight to this issue would be helpful.

    There are some characters that you cannot use in an XML document, but I was not aware that the questionmark was one of them. As far as I know, you need to transform the characters '&', '<' and '>', and any character with a code higher than 127. The fact that the question mark is turned into an upside down questionmark seems to be some weird functionality.

  • Send a record type parameter to a stored procedure

    Hi!
    I have a stored procedure, which accepts an input parameter which is a record type.
    How do I send such a parameter using ODP.NET?
    Thanks.

    Thx for sharing your expertise. keep it up.
    Your other post explaining accessing DFF attributes in controller also helpful.
    Regards,
    Anand

  • How to send HTML link in the email through BRFplus

    Hi All,
    I want to send an HTML link embedded into the email body , as shown below.
    Hello Friends,
    Please find below path for error occurred during triggering of materials.
    Http://documents/error/doc.htm
    Thanks & Regards
    Khushbu
    And when the user clicks on the HTML link , it should directly take user to the browser.
    Kindly suggest how to implement this functionality.
    Regards,
    Khushbu

    I have tried using HTML code for writing the email body, but its not working.Its not converting HTML code , its taking them as characters only.I know how pass HTML link in email from ABAP but here email are sent from SEND email action of BRFplus.

  • Send Output as attachment to email address

    Hi friends,
    My requirement is to send the Output as attachment to a specific email address.
    I have created a new output type and using transmission medium as External Send.
    If I use SH/BP/SP it is picking the mail address and working fine.
    Now my requirement is to send to fixed standard email address irrelevant of document.
    Can anyone help me to explain how can I achieve this by setting in Parner functions of that output type?
    I dont want to add any parner function in partner determination.
    Thanks in advance.
    Rgds,
    AK

    Hi there,
    Define a new customized Z table & maintain the required mail ids in the table.
    in the O/p processing prog, call the Z table & send the mail to the mail ids mentioned in it.
    For formality, assign the O/p to an partner function in your condition records.
    Regards,
    Sivanand

  • Problem in sending CSV as attachment in email

    Hi All,
    I'm working on ECC 5.0. I have an internal table with the data. I have to send this data as an attachment in an email. I sending a sample code which i used. When i try to open the attachment it is giving as warning popup 'File type is not recognized' and also the entire record in coming in the first column only.
    *& Report  ZTEST_EMAIL_SEND_ATTACH_PDF
    REPORT  ZTEST_EMAIL_SEND_ATTACH_PDF.
    class CL_ABAP_CHAR_UTILITIES definition load.
    constants:v_nl type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>newline,
         v_ht type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>horizontal_TAB,
         v_bs type ABAP_CHAR1 value CL_ABAP_CHAR_UTILITIES=>CR_LF.
    data: begin of i_records occurs 0,
            data(30) type c,
            reason(225) type c,
          end of i_records.
    DATA: v_dest LIKE tsp01-rqdest,
          v_handle LIKE sy-tabix,
          v_spool_id LIKE tsp01-rqident,
          v_rc TYPE c,
          v_errmessage(100) TYPE c,
          v_text(200) TYPE c,
          i_pdf type standard table of tline.
    DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    START-OF-SELECTION.
    i_records-data = '1002'.
    i_records-reason = 'date is empty'.
    append i_records.
    clear i_records.
    i_records-data = '1005'.
    i_records-reason = 'time is empty'.
    append i_records.
    clear i_records.
    loop at i_records.
    concatenate i_records-data i_records-reason into objbin-line separated by ','.
    concatenate v_nl objbin-line into objbin-line.
    append objbin.
    clear: i_records, objbin.
    endloop.
    perform f_mail_send.
    *&      Form  f_mail_send
          text
    -->  p1        text
    <--  p2        text
    form f_mail_send .
    DATA: i_email TYPE TABLE OF somlreci1 WITH HEADER LINE,
          i_mess TYPE TABLE OF solisti1 WITH HEADER LINE,
          w_subject TYPE so_obj_des,
         w_name TYPE so_obj_nam.
          w_name TYPE char30.
    i_email-receiver = '[email protected]'.
    APPEND i_email.
    i_mess-line = 'This is a test message. Customer Statements'.
    APPEND i_mess.
    w_name = 'Statements_345594_344455_conv'.
    w_subject = 'Your Customer Statement for'.
    PERFORM send_mail_out_raw TABLES i_email
                                     i_mess
                              USING  w_subject
                                     w_name.
    endform.                    " f_mail_send
    *&      Form  send_mail_out_raw
          text
         -->PI_EMAIL   text
         -->PI_MESS    text
         -->PI_PDF     text
         -->PV_SUBJECT text
         -->PV_NAME    text
    FORM send_mail_out_raw TABLES pi_email STRUCTURE somlreci1
                                  pi_mess STRUCTURE solisti1 "Message
                            USING pv_subject TYPE so_obj_des
                                  pv_name TYPE char30.
      DATA :
        li_receivers TYPE STANDARD TABLE OF somlreci1,
        li_head TYPE STANDARD TABLE OF solisti1,
        li_packing_list TYPE STANDARD TABLE OF sopcklsti1,
        li_pdf TYPE STANDARD TABLE OF solisti1.
      DATA : lst_doc_data TYPE sodocchgi1,
             lw_lines    TYPE i,
             lw_name(34) TYPE c,
             lw_subject TYPE sodocchgi1-obj_descr.
      DATA : lst_pemail TYPE somlreci1,
             lst_pmess TYPE solisti1,
             lst_receivers TYPE somlreci1,
             lst_head TYPE solisti1,
             lst_packing_list TYPE sopcklsti1,
             lst_mess TYPE solisti1.
      lw_subject = pv_subject.
      lw_name = pv_name.
      CONCATENATE lw_name '.csv' INTO lw_name.
      CONDENSE lw_name NO-GAPS.
    Fill the email content
      DESCRIBE TABLE pi_mess LINES lw_lines.
    Populate the subject/generic message attributes
      lst_doc_data-obj_langu = sy-langu.
      lst_doc_data-obj_name  = lw_name.
      lst_doc_data-obj_descr = lw_subject.
      READ TABLE pi_mess INTO lst_mess INDEX lw_lines.
      lst_doc_data-doc_size = ( lw_lines - 1 ) * 255 +
                              STRLEN( lst_mess ).
    Describe the body of the message
      REFRESH li_packing_list.
      lst_packing_list-transf_bin = space.
      lst_packing_list-head_start = 1.
      lst_packing_list-head_num = 0.
      lst_packing_list-body_start = 1.
      lst_packing_list-body_num = lw_lines.
      lst_packing_list-doc_type = 'RAW'.
      lst_packing_list-doc_size = ( lw_lines - 1 ) * 255 +
                                  STRLEN( lst_mess ).
      APPEND lst_packing_list TO li_packing_list.
      CLEAR lst_packing_list.
    Create attachment
      CLEAR lw_lines.
      DESCRIBE TABLE objbin LINES lw_lines.
      lst_packing_list-transf_bin = 'X'.
      lst_packing_list-head_start = 1.
      lst_packing_list-head_num   = 1.
      lst_packing_list-body_start = 1.
      lst_packing_list-body_num   = lw_lines.
      lst_packing_list-doc_type   =  'CSV'.
      lst_packing_list-obj_descr  =  lw_subject.
      lst_packing_list-obj_name   =  lw_name.
      lst_packing_list-doc_size   =  ( lw_lines ) * 255.
      APPEND lst_packing_list TO li_packing_list.
    Header
      REFRESH li_head.
      CLEAR lst_head. REFRESH li_head.
      lst_head-line = lw_name. APPEND lst_head TO li_head.
    Add the recipients email address
      REFRESH li_receivers.
      LOOP AT pi_email INTO lst_pemail.
        lst_receivers-receiver = lst_pemail-receiver.
        lst_receivers-rec_type = 'U'.
        lst_receivers-com_type = 'INT'.
        APPEND lst_receivers TO li_receivers.
        CLEAR lst_receivers.
      ENDLOOP.
    *Send mail to external address
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
         document_data              = lst_doc_data
         put_in_outbox              = 'X'
         commit_work                = 'X'
       TABLES
         packing_list               = li_packing_list
         object_header              = li_head
         contents_bin               = objbin
         contents_txt               = pi_mess
         receivers                  = li_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.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data                   = lst_doc_data
         PUT_IN_OUTBOX                    = 'X'
         COMMIT_WORK                      = 'X'
      IMPORTING
        SENT_TO_ALL                      =
        NEW_OBJECT_ID                    =
        tables
          packing_list                     = li_packing_list
         OBJECT_HEADER                    = li_head
         CONTENTS_BIN                     = objbin
         CONTENTS_TXT                     = pi_mess
        CONTENTS_HEX                     =
        OBJECT_PARA                      =
        OBJECT_PARB                      =
          receivers                        = li_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 .
      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.                    "Send_mail
    Sai

    Hi sai,
    1. I just tried it now.
    2. And it works ok now.
    3. Just make 2 corrections.
      a) replace your definition of new_line with.
    <b>constants:v_nl(2) type c value CL_ABAP_CHAR_UTILITIES=>CR_LF,</b>
    b) Instead of using    concatenate v_nl objbin-line into objbin-line.
       use
    <b>  concatenate  objbin-line v_nl into objbin-line.</b>
    regards,
    amit m.

Maybe you are looking for