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: 

Email sending

Former Member
0 Kudos

Hi All,

iam using following code iam getting in sap inbox also but iam not reciving the mail iam missing any parameters

WA_MAILDATA-obj_descr = IS_BACKMON-Message_Subject.

*Collect the mailid and reciver type to send an email

WA_RECEIVER-receiver = IS_BACKMON-DIST_LIST.

WA_RECEIVER-rec_type = c_revtype.

WA_RECEIVER-com_type = c_int.

APPEND WA_RECEIVER to i_RECEIVER.

*Display the context of the message

is_contents_txt = IS_BACKMON-Message_Body.

APPEND is_contents_txt to i_contents_txt.

clear is_contents_txt.

*Send an Email to a Particular person

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = WA_MAILDATA

put_in_outbox = c_flag

commit_work = c_flag

tables

  • object_header = I_MESSAGE

OBJECT_CONTENT = i_contents_txt

receivers = i_RECEIVER

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.

Regards

Warun

1 ACCEPTED SOLUTION

ian_maxwell2
Active Participant
0 Kudos

Here is some sample code from a program where I was using SO_NEW_DOCUMENT_ATT_SEND_API1 to send eMails. I don't remember the specifics of this API but compare it to yours and see if there is anything you're missing.

Hope it helps.

~Ian

FORM f_OutputToDistributionList
                       using
                         l_SelectionScreen type t_SelectionScreen
                         l_Document type t_HTMLDocument.

  Data:
    i_Recievers type Somlreci1 occurs 0,
    wa_Recievers type Somlreci1,
    i_Contents_Txt type SOLISTI1 occurs 0,
    wa_Contents_Txt type SOLISTI1,
    i_PackingList type SOPCKLSTI1 occurs 0,
    wa_PackingList type SOPCKLSTI1,
    i_Contents_Bin type SOLISTI1 occurs 0,
    wa_Contents_Bin type SOLISTI1,
    i_ObjectHeader type SOLISTI1 occurs 0,
    wa_ObjectHeader type SOLISTI1,
    wa_DocumentData type SODOCCHGI1,
    l_MainLines type i,
    l_AttachLines type i.

* Set distribution list
  Refresh i_Recievers.
  clear wa_Recievers.
  wa_Recievers-Receiver = l_SelectionScreen-Dist.
  wa_Recievers-rec_type = 'C'.
  append wa_Recievers to i_Recievers.

* Set document header
  clear wa_DocumentData.
  wa_DocumentData-Obj_Name = text-026.
  wa_DocumentData-Obj_Descr = text-025.

* Set email text
  Refresh i_Contents_Txt.
  clear wa_Contents_Txt.
  wa_Contents_Txt-Line = text-027.
  Append wa_Contents_Txt to i_Contents_Txt.
  clear wa_Contents_Txt.
  wa_Contents_Txt-Line = text-025.
  Append wa_Contents_Txt to i_Contents_Txt.

  describe table i_Contents_Txt lines l_MainLines.

* Set Object Header
  Refresh i_ObjectHeader.
  Clear wa_ObjectHeader.
  Concatenate text-026 '_' sy-datum into wa_ObjectHeader.
  Append wa_ObjectHeader to i_ObjectHeader.

* Set packing list for body of email
  Refresh i_PackingList.
  clear wa_PackingList.
  wa_PackingList-transf_bin = space.
  wa_PackingList-head_start = 1.
  wa_PackingList-head_num = 0.
  wa_PackingList-body_start = 1.
  wa_PackingList-body_num = l_MainLines.
  wa_PackingList-Doc_Type = 'RAW'.

  clear wa_Contents_Txt.
  Read table i_Contents_Txt
  into wa_Contents_Txt
  index l_MainLines.
  wa_DocumentData-Doc_Size =
  ( ( l_MainLines - 1 ) * 255 + strlen( wa_Contents_Txt ) ).

  Append wa_PackingList to i_PackingList.


* Set attachment data
  Refresh i_Contents_BIN.
  Append lines of l_Document-Lines to i_Contents_BIN.
  Describe table i_Contents_BIN lines l_AttachLines.


* Set packing list for attachment
  Clear wa_PackingList.
  wa_PackingList-transf_bin = 'X'.
  wa_PackingList-head_start = 1.
  wa_PackingList-head_num = 0.
  wa_PackingList-body_start = 1.
  wa_PackingList-body_num = l_AttachLines.
  wa_PackingList-doc_type = 'HTML'.
  wa_PackingList-obj_descr = text-029.

  clear wa_Contents_BIN.
  Read table i_Contents_BIN
  into wa_Contents_BIN
  index l_AttachLines.
  wa_PackingList-doc_Size =
  ( ( l_AttachLines - 1 ) * 255 + strlen( wa_Contents_BIN ) ).

  Append wa_PackingList to i_Packinglist.


* Send emails

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              = wa_DocumentData
      PUT_IN_OUTBOX              = l_SelectionScreen-SaveInOutBox
      COMMIT_WORK                = 'X'
    TABLES
      PACKING_LIST               = i_PackingList
      OBJECT_HEADER              = i_ObjectHeader
      CONTENTS_BIN               = i_Contents_Bin
      CONTENTS_TXT               = i_Contents_Txt
      RECEIVERS                  = i_Recievers
    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 E017(VIS_SD_721).
  else.
    message I018(VIS_SD_721).
  ENDIF.

ENDFORM.                    " f_OutputToDistributionList

9 REPLIES 9

ian_maxwell2
Active Participant
0 Kudos

Here is some sample code from a program where I was using SO_NEW_DOCUMENT_ATT_SEND_API1 to send eMails. I don't remember the specifics of this API but compare it to yours and see if there is anything you're missing.

Hope it helps.

~Ian

FORM f_OutputToDistributionList
                       using
                         l_SelectionScreen type t_SelectionScreen
                         l_Document type t_HTMLDocument.

  Data:
    i_Recievers type Somlreci1 occurs 0,
    wa_Recievers type Somlreci1,
    i_Contents_Txt type SOLISTI1 occurs 0,
    wa_Contents_Txt type SOLISTI1,
    i_PackingList type SOPCKLSTI1 occurs 0,
    wa_PackingList type SOPCKLSTI1,
    i_Contents_Bin type SOLISTI1 occurs 0,
    wa_Contents_Bin type SOLISTI1,
    i_ObjectHeader type SOLISTI1 occurs 0,
    wa_ObjectHeader type SOLISTI1,
    wa_DocumentData type SODOCCHGI1,
    l_MainLines type i,
    l_AttachLines type i.

* Set distribution list
  Refresh i_Recievers.
  clear wa_Recievers.
  wa_Recievers-Receiver = l_SelectionScreen-Dist.
  wa_Recievers-rec_type = 'C'.
  append wa_Recievers to i_Recievers.

* Set document header
  clear wa_DocumentData.
  wa_DocumentData-Obj_Name = text-026.
  wa_DocumentData-Obj_Descr = text-025.

* Set email text
  Refresh i_Contents_Txt.
  clear wa_Contents_Txt.
  wa_Contents_Txt-Line = text-027.
  Append wa_Contents_Txt to i_Contents_Txt.
  clear wa_Contents_Txt.
  wa_Contents_Txt-Line = text-025.
  Append wa_Contents_Txt to i_Contents_Txt.

  describe table i_Contents_Txt lines l_MainLines.

* Set Object Header
  Refresh i_ObjectHeader.
  Clear wa_ObjectHeader.
  Concatenate text-026 '_' sy-datum into wa_ObjectHeader.
  Append wa_ObjectHeader to i_ObjectHeader.

* Set packing list for body of email
  Refresh i_PackingList.
  clear wa_PackingList.
  wa_PackingList-transf_bin = space.
  wa_PackingList-head_start = 1.
  wa_PackingList-head_num = 0.
  wa_PackingList-body_start = 1.
  wa_PackingList-body_num = l_MainLines.
  wa_PackingList-Doc_Type = 'RAW'.

  clear wa_Contents_Txt.
  Read table i_Contents_Txt
  into wa_Contents_Txt
  index l_MainLines.
  wa_DocumentData-Doc_Size =
  ( ( l_MainLines - 1 ) * 255 + strlen( wa_Contents_Txt ) ).

  Append wa_PackingList to i_PackingList.


* Set attachment data
  Refresh i_Contents_BIN.
  Append lines of l_Document-Lines to i_Contents_BIN.
  Describe table i_Contents_BIN lines l_AttachLines.


* Set packing list for attachment
  Clear wa_PackingList.
  wa_PackingList-transf_bin = 'X'.
  wa_PackingList-head_start = 1.
  wa_PackingList-head_num = 0.
  wa_PackingList-body_start = 1.
  wa_PackingList-body_num = l_AttachLines.
  wa_PackingList-doc_type = 'HTML'.
  wa_PackingList-obj_descr = text-029.

  clear wa_Contents_BIN.
  Read table i_Contents_BIN
  into wa_Contents_BIN
  index l_AttachLines.
  wa_PackingList-doc_Size =
  ( ( l_AttachLines - 1 ) * 255 + strlen( wa_Contents_BIN ) ).

  Append wa_PackingList to i_Packinglist.


* Send emails

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              = wa_DocumentData
      PUT_IN_OUTBOX              = l_SelectionScreen-SaveInOutBox
      COMMIT_WORK                = 'X'
    TABLES
      PACKING_LIST               = i_PackingList
      OBJECT_HEADER              = i_ObjectHeader
      CONTENTS_BIN               = i_Contents_Bin
      CONTENTS_TXT               = i_Contents_Txt
      RECEIVERS                  = i_Recievers
    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 E017(VIS_SD_721).
  else.
    message I018(VIS_SD_721).
  ENDIF.

ENDFORM.                    " f_OutputToDistributionList

former_member188685
Active Contributor
0 Kudos

Just check in SCOT transaction, may be that is waiting state, send them manually using the Start send process (Ctrl+F7)

Former Member
0 Kudos

Hi warun,

Excute the mail in the SOST transaction.

Regards,

Sravanthi

Former Member
0 Kudos

Hi,

I got in the SCOT and i have executed still i didn't got the email

Regards

Warun

0 Kudos

I feel there is some problem with your SCOT settings. are you able to send the mails to external adress...?

Former Member
0 Kudos

Hi

It is going in completed stage it has to go In transit the only it will send an email is iam missing any paramter in the function module

Please do needful to my question

Regards

Warun

Former Member
0 Kudos

Hi warun,

I_RECLIST-RECEIVER = ' '.------>email id
I_RECLIST-EXPRESS  = 'X'.
I_RECLIST-REC_TYPE  = 'U'.
APPEND I_RECLIST.

Regards,

Sravanthi

Former Member
0 Kudos

Hi,

Iam able to send an email through SAP message but through function module iam not able to send it it the quee as completed in SCOT

Regards

Warun

Former Member
0 Kudos

HI,

just see this step-by-step procedure for sending internal table data as email, it will definately help u:

Firstly export  the data to memory using the FM LIST_FROM_MEMORY. 

CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE e000(su) WITH text-001.
ENDIF.

then i converted it into ASCII using LIST_TO_ASCI,

CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.

This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with 
cl_abap_char_utilities=>horizontal_tab.

Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.

Sample code for formatting the data for the attachment in excel format.
u2022	Format the data for excel file download 
LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.
u2022	If not new line then replace '|' by tabs 
IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.
u2022	Insert new line for the excel data 
INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:

FORM send_mail .
u2022	Define the attachment format 
lw_doc_type = 'XLS'.
u2022	Create the document which is to be sent 
lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.
u2022	Fill the document data and get size of message 
LOOP AT t_message.
lt_objtxt = t_message-line.
APPEND lt_objtxt.
ENDLOOP.

DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE lt_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_doc_chng-doc_size = 0.
ENDIF.
u2022	Fill Packing List For the body of e-mail 
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
u2022	Create the attachment (the list itself) 
DESCRIBE TABLE t_xlstab LINES lw_tab_lines.
u2022	Fill the fields of the packing_list for creating the attachment: 
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
lt_packing_list-obj_descr = w_docdesc.
lt_packing_list-doc_size = lw_tab_lines * 255.
APPEND lt_packing_list.
u2022	Fill the mail recipient list 
lt_reclist-rec_type = 'U'.
LOOP AT t_recipient_list.
lt_reclist-receiver = t_recipient_list-address.
APPEND lt_reclist.
ENDLOOP.
u2022	Finally send E-Mail 
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = lw_sent_to_all
TABLES
packing_list = lt_packing_list
object_header = lt_objhead
contents_bin = t_xlstab
contents_txt = lt_objtxt
receivers = lt_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.

Hope it will help you

Regards

Rahul sharma