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: 

sending mail externally from SAP

divya_nayudu
Participant
0 Kudos

I am tryin to send mail externally from SAP, using the FM: "SO_NEW_DOCUMENT_SEND_API1"

am setting rec_type parameter as 'U' and com_type='INT'

But for some reason, the mail is not getting listed in SOST or SCOT. ... even the SMTP is configured in the system... There is no exception also when i execute my report, and i get msg as Mail Sent. but its not showing in inbox, nor coming in sost/scot. could anyone figure out a reason? thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,,,,,

Please have a look at this......


i_maillist-receiver = i_adr6-email .
      i_maillist-com_type = '' .
      i_maillist-express = 'X' .
      i_maillist-rec_type = 'U' .
*     i_maillist-notif_del = 'X' .
      APPEND i_maillist .
endloop.



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_HEX               = T_SFLIGHT
    contents_txt               = objtxt
*      receivers                  = reclist 
*    receivers                  = reclist1
     receivers                  = i_maillist
  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.                    "process_email

Please do let me know if it's not working....

Thanks

Saurabh

9 REPLIES 9

Former Member
0 Kudos

Hi,

Check that you have got an email address set up against your user name in SU01.

Darren

Former Member
0 Kudos

Hi,

First check your userid is configured with your external id.

If not no mail will go from u r id. try it with another user id.

Regards,

Nandha

Former Member
0 Kudos

Hi,,,,,

Please have a look at this......


i_maillist-receiver = i_adr6-email .
      i_maillist-com_type = '' .
      i_maillist-express = 'X' .
      i_maillist-rec_type = 'U' .
*     i_maillist-notif_del = 'X' .
      APPEND i_maillist .
endloop.



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_HEX               = T_SFLIGHT
    contents_txt               = objtxt
*      receivers                  = reclist 
*    receivers                  = reclist1
     receivers                  = i_maillist
  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.                    "process_email

Please do let me know if it's not working....

Thanks

Saurabh

0 Kudos

saurabh how did you populate objpack ? its mandatory na.

0 Kudos

this is my code:

DATA doc_data LIKE sodocchgi1.

DATA objcont LIKE soli OCCURS 10 WITH HEADER LINE.

DATA receiver LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

WRITE 'Notification Mail'

TO doc_data-obj_descr.

CONCATENATE 'This is a test mail' ' '

INTO objcont-line SEPARATED BY space.

append objcont.

MOVE: '<email add>'' TO receiver-receiver,

  • 'INT' TO receiver-COM_TYPE,

'U' TO receiver-REC_TYPE.

append receiver.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = doc_data

DOCUMENT_TYPE = 'RAW'

  • PUT_IN_OUTBOX = ' '

  • COMMIT_WORK = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

  • OBJECT_HEADER =

OBJECT_CONTENT = objcont

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = 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

.

is thr any error in it?

0 Kudos

Hi,

Try setting COMMIT_WORK = 'X'

Darren

0 Kudos

That solved my problem!! Thanks a lottt!! have given points!

0 Kudos

Working now.

former_member342104
Participant
0 Kudos

hi

try to this code

PERFORM SEND_EMAIL1.

FORM SEND_EMAIL1 .

DATA: LT_TEXT LIKE ZSVFILE OCCURS 0 WITH HEADER LINE.

DATA: BINARY_CONTENT TYPE SOLIX_TAB.

DATA: XL_CONTENT TYPE XSTRING.

DATA: OUTPUT TYPE STRING.

DATA : V_RECIPIENT LIKE ADR6-SMTP_ADDR.

DATA : WTABIX LIKE SY-TABIX.

WTABIX = SY-TABIX.

FREE: SEND_REQUEST,

DOCUMENT ,

SENDER ,

RECIPIENT ,

BCS_EXCEPTION.

CONCATENATE 'Sales & Stock Transfer Register' '_'

SY-DATUM+6(2) '.'

SY-DATUM+4(2) '.'

SY-DATUM+0(4) INTO HEADERTXT.

WSUBJECT = HEADERTXT.

TRY.

  • -------- create persistent send request ------------------------

SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

APPEND 'Dear Sir/Madam,' TO WTEXT1.

APPEND ' ' TO WTEXT1.

CONCATENATE 'Please find the Register as per the selections'

'entered by you.' INTO WTEXT SEPARATED BY SPACE.

APPEND WTEXT TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND 'This is a System generated automatic E-Mail Message. '

TO WTEXT1.

APPEND 'This does not require a Signature. ' TO WTEXT1.

APPEND ' ' TO WTEXT1.

APPEND 'Please do not reply.' TO WTEXT1.

APPEND ' ' TO WTEXT1.

DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

I_TYPE = 'RAW'

I_TEXT = WTEXT1

  • I_LENGTH = '12'

I_SUBJECT = HEADERTXT ).

  • BCS expects document content here e.g. from document upload

  • binary_content = ...

**>> Convert internal table to text(255)

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

TABLES

I_TAB_SAP_DATA = ITAB

I_TAB_CONVERTED_DATA = LT_TEXT

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2.

REFRESH WTEXT1.

LOOP AT LT_TEXT .

  • wtext = lt_text.

  • APPEND wtext TO wtext1.

WTEXT_3 = LT_TEXT.

APPEND WTEXT_3 TO WTEXT3.

CLEAR WTEXT_3.

ENDLOOP.

**>> Insert Header Line

LOOP AT GT_FIELDCAT INTO LS_FIELDCAT.

IF SY-TABIX = 1.

WTEXT_3 = LS_FIELDCAT-SELTEXT_L.

ELSE.

CONCATENATE WTEXT_3

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

LS_FIELDCAT-SELTEXT_L

INTO WTEXT_3.

ENDIF.

ENDLOOP.

INSERT WTEXT_3 INTO WTEXT3 INDEX 1.

CLEAR: XL_CONTENT.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

IMPORTING

BUFFER = XL_CONTENT

TABLES

TEXT_TAB = WTEXT3

EXCEPTIONS

FAILED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

ENDIF.

REFRESH BINARY_CONTENT .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

BUFFER = XL_CONTENT

TABLES

BINARY_TAB = BINARY_CONTENT.

CALL METHOD DOCUMENT->ADD_ATTACHMENT

EXPORTING

I_ATTACHMENT_TYPE = 'XLS'

I_ATTACHMENT_SUBJECT = WSUBJECT

I_ATT_CONTENT_HEX = BINARY_CONTENT.

  • add document to send request

CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).

  • --------- set sender -------------------------------------------

SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ).

CALL METHOD SEND_REQUEST->SET_SENDER

EXPORTING

I_SENDER = SENDER.

PERFORM DETERMINE_MAIL_RECEPIENTS.

  • ---------- send document ---------------------------------------

CALL METHOD SEND_REQUEST->SEND(

EXPORTING

I_WITH_ERROR_SCREEN = 'X'

RECEIVING

RESULT = SENT_TO_ALL ).

COMMIT WORK.

CATCH CX_BCS INTO BCS_EXCEPTION.

WRITE: 'Error in Sending Mail'.

WRITE: 'Error Type:'(002), BCS_EXCEPTION->ERROR_TYPE.

EXIT.

ENDTRY.

ENDFORM. " send_email1

FORM DETERMINE_MAIL_RECEPIENTS .

DATA : V_RECIPIENT LIKE ADR6-SMTP_ADDR.

DATA : WTABIX LIKE SY-TABIX.

WTABIX = SY-TABIX.

LOOP AT emailed_input.

WTABIX = SY-TABIX.

  • CHECK NOT adr6-smtp_addr IS INITIAL.

V_RECIPIENT = emailed_input-LOW.

RECIPIENT =

CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( V_RECIPIENT ).

CALL METHOD SEND_REQUEST->ADD_RECIPIENT

EXPORTING

I_RECIPIENT = RECIPIENT

I_EXPRESS = 'X'.

ENDLOOP.

ENDFORM.