Application Development and Automation 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: 
Read only

SO_NEW_DOCUMENT_ATT_SEND_API1----Customizing Sender

Former Member
0 Likes
3,854

Hi Experts,

We are using FM "SO_NEW_DOCUMENT_ATT_SEND_API1" to send email to customer. This FM is taking sy-uname as the default sender of email. we need to customize the sender of the email. Does anyone has worked on similar requirement or anyone knows how to achieve this? Please provide inputs.

Thanks in advance.

Preeti

8 REPLIES 8
Read only

Former Member
0 Likes
2,086

Hi,

You can get the email address from table ADR6 the field is SMTP_ADDR.

regards,

Rahul

Read only

0 Likes
2,086

following code will resolve ur query.

data : p_sender type somlreci1-receiver value 'your email address', "Sender Email

ld_sender_address like soextreci1-receiver,

ld_sender_address_type like soextreci1-adr_typ.

ld_sender_address = p_sender.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = gs_docdata

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

contents_bin = gt_objbin

receivers = gt_reclist

contents_txt = it_mess_bod

object_header = objhead

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.

Read only

koolspy_ultimate
Active Contributor
0 Likes
2,086

Hi please try this [wiki session|http://wiki.sdn.sap.com/wiki/display/Snippets/Tosendamailattachmentwithmorethan255charactersinaline]


DATA: w_subject LIKE sodocchgi1,
      i_pack_list LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
      i_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
      i_contents_text LIKE solisti1 OCCURS 10 WITH HEADER LINE,      "FOR MAIL CONTENTS
      i_contents_bin TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE, 
      i_contents_hex TYPE STANDARD TABLE OF solix WITH HEADER LINE,    "for attachment
      i_receiver LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
      content_out LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: li_contents_hex TYPE STANDARD TABLE OF solix WITH HEADER LINE.
  lv_hex1 = cl_abap_char_utilities=>cr_lf.

*Create the body of the attachment file of the mail INTO li_contents_bin-line SEPARATED BY lc_tab.
  CONCATENATE li_contents_bin-line lv_hex1 INTO li_contents_bin-line.
  APPEND li_contents_bin.

*Converting the table contents for attachment to xstring 
  LOOP AT li_contents_bin.
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text           = li_contents_bin-line
      IMPORTING
        buffer         = li_contents-line
     EXCEPTIONS
       failed         = 1
       OTHERS         = 2.

*Converting the table contents from xstring to binary
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer                = li_contents-line
*        APPEND_TO_TABLE       = 'I_CONTENTS_HEX'
      TABLES
        binary_tab            = li_contents_hex.
              
    LOOP AT li_contents_hex.
      APPEND li_contents_hex TO i_contents_hex .
    ENDLOOP.

* FM called for sending the mail to the intended recipients
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                    = w_subject
      put_in_outbox                    = 'X'
      commit_work                      = 'X'
    IMPORTING
      sent_to_all                      = sent_to_all
    TABLES
      packing_list                     = i_pack_list
      object_header                    = i_objhead
      contents_hex                     = i_contents_hex
      contents_txt                     = i_contents_text
      receivers                        = i_receiver.   
*/

Regards,

koolspy.

Read only

Former Member
0 Likes
2,085

instead of using FM "SO_NEW_DOCUMENT_ATT_SEND_API1" use the FM 'SO_DOCUMENT_SEND_API1'

and passs te sender's address in sender_address .

something like this .

sender_address = 'test'

Read only

Former Member
0 Likes
2,085

Hi,

Follow the below code....

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.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = ' | '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

  • Creating the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'BMP'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'Email Address'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

RECLIST-REC_TYPE = 'P'.

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.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of' 'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

Ram.

Read only

Former Member
0 Likes
2,085

I think I read in this forum that one of the API's allows a modification of the sender, and one does not. I believe that SO_NEW_DOCUMENT_ATT_SEND_API1, but the one without the attachment allows modification of the sender e-mail addr.

Read only

Former Member
0 Likes
2,085

Hi Experts,

Thanks a lot for your inputs.

My query is resolved. Now, I am using FM 'SO_DOCUMENT_SEND_API1' which allows to set the sender instead of FM SO_NEW_DOCUMENT_ATT_SEND_API1.

Regards,

Preeti

Read only

soham_zendekar27
Discoverer
0 Likes
2,085

You can pass the user id to an 'SY-UNAME' before calling FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.