Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP send external email

0 Kudos
224

I use FM SO_OBJECT_SEND to send external email in my Z program but the output always in attachment format, depend on the format i specified (pdf,htm,txt,xls). I want the output to be in standard email body. How to do it?

1 ACCEPTED SOLUTION

Madhurivs23
Participant
0 Kudos
145
8 REPLIES 8

sudhahar_ramachandran
Active Participant
0 Kudos
145

you have to write the output in the email body insetad of making it as attachment. its always better to keep it as an attachment as we do not know how long the report output will be.

with regards,

Sudhahar R.

RemiKaimal
Active Contributor
0 Kudos
145

Hello,

Check the importing Parameter : objcont .

This will hold the data for the body of the message.

att_cont holds the attachment contents

For message body the format should be in RAW

Formats for attachment:

XLS=>Excel file

RAW=>Text file

PDF=>PDF file

Cheers,

Remi

jaideepsharma
Active Contributor
0 Kudos
145

Hi,

Can you please send your code or check if you are passing att_cont parameter in your function module. I would suggest you to use SO_NEW_DOCUMENT_SEND_API1 function module to send mail.

Also find the code below for your reference.

 REPORT  z_test_email_sending.
DATA:  t_reclist TYPE TABLE OF somlreci1,
      wa_receiver LIKE LINE OF t_reclist,
      objcont TYPE TABLE OF solisti1,
     subject TYPE TABLE OF solisti1,
     objline TYPE solisti1,
      w_line_count   TYPE i,
        doc_chng TYPE sodocchgi1,
        offset type i.

CONSTANTS c_sep  TYPE c VALUE '|'.

DATA : BEGIN OF mail_line OCCURS 0,
      sep0,
      model_year(6),
      sep1,
      mf(4),
      sep2,
      type(5),
      sep3,
      variant(14),
      sep4,
      kitype(5),
      sep5,
      option(8),
      sep6,
      color(8),
      sep7,
      uph(11),
      sep8,
      struc_week(10),
      sep9,
    END OF mail_line.

*construct the message and the e-mail
wa_receiver-receiver = receivers mail id.
* Email Subject
doc_chng-obj_name = 'test mail'.
MOVE 'Cost Error from SAP' TO doc_chng-obj_descr.


doc_chng-obj_langu = sy-langu.
*    doc_chng-SENSITIVTY = 'P'.

* Email body
CLEAR objline.

CONCATENATE 'This is an automatically generated email'
'Please do not reply to this email.'
INTO   objline SEPARATED BY space.
APPEND objline TO objcont.
CLEAR objline.
APPEND objline TO objcont.

CONCATENATE 'Cost errors in SAP as on' sy-datum INTO
objline SEPARATED BY space.
APPEND objline TO objcont.
CLEAR objline.
CLEAR objline.
APPEND objline TO objcont.

* horizontal line at beginning of records
DO 80 TIMES.
  IF sy-index = 1.
*   objline+sy-index(1) = ' '.
    continue.
  ELSE.
    offset = sy-index - 1.
    objline+offset(1) = '-'.
  ENDIF.
ENDDO.

clear offset.

APPEND objline TO objcont.
CLEAR objline.

mail_line-sep0 = c_sep.
mail_line-model_year = 'Model Yr'.
mail_line-sep1 = c_sep.
mail_line-mf = 'Mf'.
mail_line-sep2 = c_sep.
mail_line-type = 'Type'.
mail_line-sep3 = c_sep.
mail_line-variant = 'Variant'.
mail_line-sep4 = c_sep.
mail_line-kitype = 'Ki-type'.
mail_line-sep5 = c_sep.
mail_line-option = 'Option'.
mail_line-sep6 = c_sep.
mail_line-color = 'Color'.
mail_line-sep7 = c_sep.
mail_line-uph = 'Upholstery'.
mail_line-sep8 = c_sep.
mail_line-struc_week = 'Str_week'.
mail_line-sep9 = c_sep.
MOVE mail_line TO objline.
APPEND objline TO objcont.
CLEAR mail_line.

CLEAR objline.

* horizontal line at beginning of records
*horizontal line at beginning of records
DO 80 TIMES.
  IF sy-index = 1.
*   objline+sy-index(1) = ' '.
    continue.
  ELSE.
    offset = sy-index - 1.
    objline+offset(1) = '-'.
  ENDIF.
ENDDO.

clear offset.

APPEND objline TO objcont.CLEAR objline.

DO 5 TIMES.

  mail_line-sep0 = c_sep.
  mail_line-model_year = 'xxxx'.
  mail_line-sep1 = c_sep.
  mail_line-mf = 'xxx'.
  mail_line-sep2 = c_sep.
  mail_line-type = 'xxx'.
  mail_line-sep3 = c_sep.
  mail_line-variant = 'xxxx xxxxx'.
  mail_line-sep4 = c_sep.
  mail_line-kitype = 'xxx'.
  mail_line-sep5 = c_sep.
  mail_line-option = 'xxxxxx'.
  mail_line-sep6 = c_sep.
  mail_line-color = 'xxxxxx'.
  mail_line-sep7 = c_sep.
  mail_line-uph = 'xxxxxx'.
  mail_line-sep8 = c_sep.
  mail_line-struc_week = 'xxxxxx'.
  mail_line-sep9 = c_sep.
  MOVE mail_line TO objline.
  APPEND objline TO objcont.

ENDDO.

CLEAR objline.

*horizontal line at beginning of records
DO 80 TIMES.
  IF sy-index = 1.
*   objline+sy-index(1) = ' '.
    continue.
  ELSE.
    offset = sy-index - 1.
    objline+offset(1) = '-'.
  ENDIF.
ENDDO.

clear offset.

APPEND objline TO objcont.
CLEAR objline.

wa_receiver-rec_type = 'U'.
wa_receiver-com_type = 'INT'.
APPEND wa_receiver TO t_reclist.

.
*   size
DESCRIBE TABLE objcont LINES w_line_count.
READ TABLE objcont INDEX w_line_count INTO objline.
doc_chng-doc_size = ( w_line_count - 1 ) * 255 +
                       STRLEN( objline ).


CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
              EXPORTING
                document_data              = doc_chng
                document_type              = 'RAW'
*                  put_in_outbox              = ' '
                commit_work                = 'X'
              TABLES
*                  object_header             = subject
                object_content             = objcont
                receivers                  = t_reclist
              EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                operation_no_authorization = 4
                OTHERS                     = 9.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

KR Jaideep,

Former Member
0 Kudos
145

Hi,

Use the format 'RAW'. you will get in body.

Thanks and regards,

Venkat

Former Member
0 Kudos
145

Use FM "SO_NEW_DOCUMENT_ATT_SEND_API1".

Former Member
0 Kudos
145

Use the following code.

DATA : doc_chng TYPE sodocchgi1,

objpack TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,

objhead TYPE solisti1 OCCURS 0 WITH HEADER LINE,

objbin TYPE solisti1 OCCURS 0 WITH HEADER LINE,

reclist TYPE somlreci1 OCCURS 0 WITH HEADER LINE.

reclist-receiver = email address.

reclist-rec_type = 'U'.

reclist-com_type = 'INT'.

APPEND reclist.

l_objbin-line = 'Hai how are you?'.

APPEND l_objbin TO objbin.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

objpack-obj_name = text-018.

objpack-obj_descr = text-019.

objpack-doc_size = tab_lines * 255.

APPEND objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

COMMIT WORK AND WAIT.

SUBMIT rsconn01

WITH mode = 'INT'

WITH output = ' '

AND RETURN.

Madhurivs23
Participant
0 Kudos
146

Former Member
0 Kudos
145

I had used the 'RAW' but it produce pdf attachment. I want the message to be in email body because it is just payment notification and very short content. Moreover my client want this way.

I also had use SO_NEW_DOCUMENT_SEND_API1 but it produce the same result.

is there any configuration involved in this? i have check transaction code SCOT, i cant see the format configuration.

Edited by: imax80 on Jun 9, 2009 3:33 PM

Edited by: imax80 on Jun 9, 2009 3:44 PM