cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Automatic Mail to external

Former Member
0 Kudos

Hi,

I am having 1 requirement that after save the Sales Order that data should go to external mail.

how to send that output to external mail and give me code for that also.

This is very urgent

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First configure the settings required for sending mail in SCOT Tcode and for sending FAX.

Use the fun modules

SO_NEW_DOCUMENT_ATT_SEND_API1 for sending mail.

see the sample code:

Mailing with Attachment by ABAP Coding

Refer this link:

FORM send_list_to_basis .

DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,

lt_index TYPE sy-tabix,

doc_type(3) TYPE c,

descr LIKE it_objpack_basis-obj_descr,

temp_data LIKE w_path,

temp1 TYPE string,

tab_lines TYPE i,

langu(15) TYPE c,

expirydate TYPE so_obj_edt,

L_FILE1(100).

CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.

W_PATH-FILENAME = L_FILE1.

APPEND w_path.

CLEAR w_path.

wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.

wa_doc_chng-obj_langu = 'E'.

wa_doc_chng-obj_expdat = sy-datum.

CLEAR w_subject.

CONCATENATE 'Please find attached document with list of users'

'not logged on for 180 days for client' sy-mandt

INTO w_subject SEPARATED BY space.

it_objtxt_basis-line = w_subject.

APPEND it_objtxt_basis.

CLEAR it_objtxt_basis.

it_objtxt_basis-line = text-004.

APPEND it_objtxt_basis.

CLEAR it_objtxt_basis.

CLEAR w_tab_line.

DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.

READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.

wa_doc_chng-doc_size =

( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).

CLEAR it_objpack_basis-transf_bin.

it_objpack_basis-head_start = 1.

it_objpack_basis-head_num = 0.

it_objpack_basis-body_start = 1.

it_objpack_basis-body_num = w_tab_line.

it_objpack_basis-doc_type = 'RAW'.

APPEND it_objpack_basis.

CLEAR it_objpack_basis.

LOOP AT w_path.

temp1 = w_path.

descr = w_path.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = descr

lang = 'E'

IMPORTING

rstring = descr.

CALL FUNCTION 'STRING_SPLIT'

EXPORTING

delimiter = '\'

string = descr

IMPORTING

head = descr

tail = temp_data.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = descr

lang = 'E'

IMPORTING

rstring = descr.

CALL FUNCTION 'STRING_SPLIT'

EXPORTING

delimiter = '.'

string = descr

IMPORTING

head = temp_data

tail = doc_type.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = temp1

filetype = 'BIN'

header_length = 0

read_by_line = 'X'

replacement = '#'

TABLES

data_tab = it_upload.

DESCRIBE TABLE it_upload LINES tab_lines.

DESCRIBE TABLE it_objbin_basis LINES lt_index.

lt_index = lt_index + 1.

LOOP AT it_upload.

wa_objbin_basis-line = it_upload-line.

APPEND wa_objbin_basis TO it_objbin_basis.

CLEAR wa_objbin_basis.

ENDLOOP.

it_objpack_basis-transf_bin = 'X'.

it_objpack_basis-head_start = 0.

it_objpack_basis-head_num = 0.

it_objpack_basis-body_start = lt_index.

it_objpack_basis-body_num = tab_lines.

it_objpack_basis-doc_type = doc_type.

it_objpack_basis-obj_descr = descr.

it_objpack_basis-doc_size = tab_lines * 255.

APPEND it_objpack_basis.

CLEAR it_objpack_basis.

ENDLOOP.

it_reclist_basis-receiver = 'XXX@.com'.

it_reclist_basis-rec_type = 'U'.

APPEND it_reclist_basis.

CLEAR it_reclist_basis.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = it_objpack_basis

contents_txt = it_objtxt_basis

contents_bin = it_objbin_basis

receivers = it_reclist_basis

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc EQ 0.

SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

ENDIF.

ENDFORM. " send_list_to_basis

OR

Here is a simple example program.

report zrich_0003 .

data: maildata like sodocchgi1.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: list type table of abaplist with header line.

data: ascilines(1024) type c occurs 0 with header line.

data: htmllines type table of w3html with header line.

start-of-selection.

submit <zreport> exporting list to memory and return.

call function 'LIST_FROM_MEMORY'

tables

listobject = list

exceptions

not_found = 1

others = 2.

call function 'LIST_TO_ASCI'

tables

listobject = list

listasci = ascilines

exceptions

empty_list = 1

list_index_invalid = 2

others = 3.

call function 'WWW_HTML_FROM_LISTOBJECT'

tables

html = htmllines

listobject = list.

clear: maildata, mailtxt, mailrec.

refresh: mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test Subject'.

loop at htmllines.

mailtxt = htmllines.

append mailtxt.

endloop.

mailrec-receiver = 'you@yourcompany'.

mailrec-rec_type = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'HTM'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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.

This will trigger the send process in SAPconnent

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

Please refer to the link below:

http://www.sapdev.co.uk/reporting/email/emailhome.htm

Please check below link.

http://www.sapdev.co.uk/reporting/rep_spooltopdf2.htm

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I will ask you to go to transaction SCOT & SOST, these are the two basic transactions related to output type for sending emails.

Here you have to speak to your basis guy and ensure that the server is configured to send emails.

Also you have to maintain the email address of the customer for sending emails in customer master.

This will take care of the process for sending emails (Output Type MAIL - Transmission Medium = 5 )

Also make sure you have kept the setting as "4" SEND IMMEDIEATELY.

Check the below ABAP code for sending mails.



PARAMETERS: p_mail TYPE ad_smtpadr OBLIGATORY.
 
DATA: i_mara TYPE STANDARD TABLE OF mara,  " MARA Entries
      i_marc TYPE STANDARD TABLE OF marc.  " MARC Entries
DATA: l_text TYPE char255.  " Text
DATA: l_lines TYPE i,
      l_size            TYPE           sood-objlen.
" Size of Attachment
 
 
* Mail related
DATA: i_content         TYPE   soli_tab, " Mail content
      i_attach          TYPE   soli_tab, " Attachment
      i_attach1         TYPE   soli_tab. " Attachment
 
DATA: l_send_request    TYPE REF TO    cl_bcs,
                                            " E-Mail Send Request
      l_document        TYPE REF TO    cl_document_bcs,
                                            " E-Mail Attachment
      l_recipient       TYPE REF TO    if_recipient_bcs,
                                            " Distribution List
      l_sender          TYPE REF TO    if_sender_bcs,
                                            " Address of Sender
      l_uname           TYPE           salrtdrcpt,
                                            " Sender Name(SY-UNAME)
      l_bcs_exception   TYPE REF TO    cx_document_bcs,
                                            " BCS Exception
      l_addr_exception  TYPE REF TO    cx_address_bcs,
                                            " Address Exception
      l_send_exception  TYPE REF TO    cx_send_req_bcs.
" E-Mail sending Exception
 
*Constants------------------------------------------------------------*
CONSTANTS: c_tab(1) TYPE c VALUE
               cl_abap_char_utilities=>horizontal_tab,
                                     " Tab Character
 
           c_cr(1)  TYPE c VALUE cl_abap_char_utilities=>cr_lf,
                                     " Line Feed for End-Of_line
 
           c_ext    TYPE soodk-objtp VALUE 'XLS'. " XLS Extension
 
START-OF-SELECTION.
 
  SELECT * FROM mara INTO TABLE i_mara UP TO 20 ROWS.
 
  SELECT * FROM marc INTO TABLE i_marc UP TO 20 ROWS.
 
* Preparing body of the Mail
  MOVE 'Mail Body' TO l_text.
  APPEND l_text TO i_content.
 
* Creates persistent send request
  TRY.
      l_send_request = cl_bcs=>create_persistent( ).
 
* Creating Document
      l_document = cl_document_bcs=>create_document(
                                    i_type  = 'RAW'
                                    i_text  = i_content[]
                                    i_subject = 'Material Details' ).
 
* Preparing contents of attachment with Change Log
  PERFORM prepare_attachment.
 
  DESCRIBE TABLE i_mara LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
      l_size = l_lines * 2 * 255.
 
* Adding Attachment
      CALL METHOD l_document->add_attachment
        EXPORTING
          i_attachment_type    = c_ext
          i_attachment_size    = l_size
          i_attachment_subject = 'Material Details'
          i_att_content_text   = i_attach[].
 
  DESCRIBE TABLE i_marc LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
      l_size = l_lines * 2 * 255.
 
* Adding Attachment
      CALL METHOD l_document->add_attachment
        EXPORTING
          i_attachment_type    = c_ext
          i_attachment_size    = l_size
          i_attachment_subject = 'Material Plant Details'
          i_att_content_text   = i_attach1[].
 
 
* Add document to send request
      CALL METHOD l_send_request->set_document( l_document ).
 
* Get Sender Object
      l_uname = sy-uname.
 
      l_sender = cl_sapuser_bcs=>create( l_uname ).
 
      CALL METHOD l_send_request->set_sender
        EXPORTING
          i_sender = l_sender.
 
* E-Mail
      TRANSLATE p_mail TO LOWER CASE.
 
    l_recipient = cl_cam_address_bcs=>create_internet_address( p_mail )
.
 
      CALL METHOD l_send_request->add_recipient
        EXPORTING
          i_recipient  = l_recipient
          i_express    = 'U'
          i_copy       = ' '
          i_blind_copy = ' '
          i_no_forward = ' '.
 
 
*Trigger E-Mail immediately
      l_send_request->set_send_immediately( 'X' ).
 
      CALL METHOD l_send_request->send( ).
 
      COMMIT WORK.
 
    CATCH cx_document_bcs INTO l_bcs_exception.
 
    CATCH cx_send_req_bcs INTO l_send_exception.
 
    CATCH cx_address_bcs  INTO l_addr_exception.
 
  ENDTRY.
 
 
*&---------------------------------------------------------------------
*
*&      Form  PREPARE_ATTACHMENT
*&---------------------------------------------------------------------
*
FORM prepare_attachment.
 
  FIELD-SYMBOLS: <lfs_table>,    " Internal table structure
                 <lfs_con>.      " Field Content
  DATA: l_text TYPE char1024.     " Text content for mail attachment
  DATA: l_con(50) TYPE c.        " Field Content in character format
 
* Columns to be tab delimeted
  LOOP AT i_mara ASSIGNING <lfs_table>.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
             TO <lfs_con>.
      IF sy-subrc NE 0.
        CONCATENATE c_cr l_text INTO l_text.
        APPEND l_text TO i_attach.
        EXIT.
      ELSE.
        CLEAR: l_con.
        MOVE <lfs_con> TO l_con.
        CONDENSE l_con.
        IF sy-index = 1.
          CLEAR: l_text.
          MOVE l_con TO l_text.
        ELSE.
          CONCATENATE l_text l_con INTO l_text
             SEPARATED BY c_tab.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDLOOP.
 
  LOOP AT i_marc ASSIGNING <lfs_table>.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
             TO <lfs_con>.
      IF sy-subrc NE 0.
        CONCATENATE c_cr l_text INTO l_text.
        APPEND l_text TO i_attach1.
        EXIT.
      ELSE.
        CLEAR: l_con.
        MOVE <lfs_con> TO l_con.
        CONDENSE l_con.
        IF sy-index = 1.
          CLEAR: l_text.
          MOVE l_con TO l_text.
        ELSE.
          CONCATENATE l_text l_con INTO l_text
             SEPARATED BY c_tab.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDLOOP.
 
ENDFORM.                    " PREPARE_ATTACHMENT
 

Please treat above code just as reference...

For more information, check the below link.

[|]

Reward points if helpful.

Thanks,

Balaji

Former Member
0 Kudos

First configure the settings required for sending mail in SCOT Tcode and for sending FAX.

Use the fun modules

SO_NEW_DOCUMENT_ATT_SEND_API1 for sending mail.

see the sample code:

Mailing with Attachment by ABAP Coding

Refer this link:

FORM send_list_to_basis .

DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,

lt_index TYPE sy-tabix,

doc_type(3) TYPE c,

descr LIKE it_objpack_basis-obj_descr,

temp_data LIKE w_path,

temp1 TYPE string,

tab_lines TYPE i,

langu(15) TYPE c,

expirydate TYPE so_obj_edt,

L_FILE1(100).

CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.

W_PATH-FILENAME = L_FILE1.

APPEND w_path.

CLEAR w_path.

wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.

wa_doc_chng-obj_langu = 'E'.

wa_doc_chng-obj_expdat = sy-datum.

CLEAR w_subject.

CONCATENATE 'Please find attached document with list of users'

'not logged on for 180 days for client' sy-mandt

INTO w_subject SEPARATED BY space.

it_objtxt_basis-line = w_subject.

APPEND it_objtxt_basis.

CLEAR it_objtxt_basis.

it_objtxt_basis-line = text-004.

APPEND it_objtxt_basis.

CLEAR it_objtxt_basis.

CLEAR w_tab_line.

DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.

READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.

wa_doc_chng-doc_size =

( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).

CLEAR it_objpack_basis-transf_bin.

it_objpack_basis-head_start = 1.

it_objpack_basis-head_num = 0.

it_objpack_basis-body_start = 1.

it_objpack_basis-body_num = w_tab_line.

it_objpack_basis-doc_type = 'RAW'.

APPEND it_objpack_basis.

CLEAR it_objpack_basis.

LOOP AT w_path.

temp1 = w_path.

descr = w_path.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = descr

lang = 'E'

IMPORTING

rstring = descr.

CALL FUNCTION 'STRING_SPLIT'

EXPORTING

delimiter = '\'

string = descr

IMPORTING

head = descr

tail = temp_data.

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = descr

lang = 'E'

IMPORTING

rstring = descr.

CALL FUNCTION 'STRING_SPLIT'

EXPORTING

delimiter = '.'

string = descr

IMPORTING

head = temp_data

tail = doc_type.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = temp1

filetype = 'BIN'

header_length = 0

read_by_line = 'X'

replacement = '#'

TABLES

data_tab = it_upload.

DESCRIBE TABLE it_upload LINES tab_lines.

DESCRIBE TABLE it_objbin_basis LINES lt_index.

lt_index = lt_index + 1.

LOOP AT it_upload.

wa_objbin_basis-line = it_upload-line.

APPEND wa_objbin_basis TO it_objbin_basis.

CLEAR wa_objbin_basis.

ENDLOOP.

it_objpack_basis-transf_bin = 'X'.

it_objpack_basis-head_start = 0.

it_objpack_basis-head_num = 0.

it_objpack_basis-body_start = lt_index.

it_objpack_basis-body_num = tab_lines.

it_objpack_basis-doc_type = doc_type.

it_objpack_basis-obj_descr = descr.

it_objpack_basis-doc_size = tab_lines * 255.

APPEND it_objpack_basis.

CLEAR it_objpack_basis.

ENDLOOP.

it_reclist_basis-receiver = 'XXX@.com'.

it_reclist_basis-rec_type = 'U'.

APPEND it_reclist_basis.

CLEAR it_reclist_basis.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = it_objpack_basis

contents_txt = it_objtxt_basis

contents_bin = it_objbin_basis

receivers = it_reclist_basis

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc EQ 0.

SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

ENDIF.

ENDFORM. " send_list_to_basis

OR

Here is a simple example program.

report zrich_0003 .

data: maildata like sodocchgi1.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: list type table of abaplist with header line.

data: ascilines(1024) type c occurs 0 with header line.

data: htmllines type table of w3html with header line.

start-of-selection.

submit <zreport> exporting list to memory and return.

call function 'LIST_FROM_MEMORY'

tables

listobject = list

exceptions

not_found = 1

others = 2.

call function 'LIST_TO_ASCI'

tables

listobject = list

listasci = ascilines

exceptions

empty_list = 1

list_index_invalid = 2

others = 3.

call function 'WWW_HTML_FROM_LISTOBJECT'

tables

html = htmllines

listobject = list.

clear: maildata, mailtxt, mailrec.

refresh: mailtxt, mailrec.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test Subject'.

loop at htmllines.

mailtxt = htmllines.

append mailtxt.

endloop.

mailrec-receiver = 'you@yourcompany'.

mailrec-rec_type = 'U'.

append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'HTM'

put_in_outbox = 'X'

tables

object_header = mailtxt

object_content = mailtxt

receivers = mailrec

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.

  • This will trigger the send process in SAPconnent

  • submit rsconn01 with mode = 'INT'

  • with output = 'X'

  • and return.

Please refer to the link below:

http://www.sapdev.co.uk/reporting/email/emailhome.htm

Please check below link.

http://www.sapdev.co.uk/reporting/rep_spooltopdf2.htm

Reward points..