Skip to Content
author's profile photo Former Member
Former Member

send outlook mail from SAP- urgent help me

Hi

I am using FM SO_NEW_DOCUMENT_SEND_API1 to send mail. Following code sy-subrc is 0. but i din nt receive mail. pls help me.

REPORT Z_MAIL.
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.

start-of-selection.

clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.

maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.

mailtxt-line = 'This is a test'.
append mailtxt.

mailrec-receiver = 'name.company.com'.
mailrec-rec_type = 'U'.
append mailrec.

call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
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.
*if sy-subrc = 0.   "( did not receive any mail) *
write : 'mail sent'.
endif.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 01:52 PM

    REPORT z_email_test1.

    TABLES:

    spfli.

    DATA:

    t_spfli LIKE TABLE OF spfli.

    DATA:

    objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

    objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    objhex LIKE solix OCCURS 0 WITH HEADER LINE,

    objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

    DATA:

    doc_chng LIKE sodocchgi1.

    CONSTANTS:

    • This is constant for Horizontal Tab.

    con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

    • This is for Line feed and Carreige return.

    con_cret(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf.

    DATA:

    w_string TYPE string,

    w_tempstring TYPE string,

    w_tablines LIKE sy-tabix.

    • Here Document details will be filled

    doc_chng-obj_name = 'SPFLI'.

    doc_chng-obj_descr = 'Spfli table contents'.

    • If the Priority is '1' then the mail will go with High priority

    • If it is '9' then the mail will go with Low priority

    • If nothing is given then there will be no priority.

    doc_chng-priority = '1'.

    • Getting Flight data

    SELECT * FROM spfli INTO TABLE t_spfli.

    • This is the Boby of the mail

    objtxt = 'Hi,'.

    APPEND objtxt.

    objtxt = 'These are the contents of Flight data'.

    APPEND objtxt.

    objtxt = 'Have fun and Enjoy'.

    APPEND objtxt.

    DESCRIBE TABLE objtxt LINES w_tablines.

    READ TABLE objtxt INDEX w_tablines.

    doc_chng-doc_size = ( w_tablines - 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 = w_tablines.

    objpack-doc_type = 'RAW'.

    APPEND objpack.

    DATA:

    w_fltime(10) TYPE c,

    w_period(3) TYPE c,

    w_distance(11) TYPE c,

    data_tab LIKE TABLE OF solisti1,

    sent_to_all TYPE sonv-flag,

    new_object_id TYPE sofolenti1-object_id.

    • Here the data needs to be converted to respective format.

    • First the entire table data will be converted into a string

    • After that string will be converted to ITAB with

    • line type of 255 characters

    CLEAR w_string.

    LOOP AT t_spfli INTO spfli.

    MOVE: spfli-fltime TO w_fltime,

    spfli-distance TO w_distance,

    spfli-period TO w_period.

    CLEAR w_tempstring.

    • Here each field will be seerated by 'Tab' and for every row

    • 'Carriage Return and Line Feed' will be used

    CONCATENATE spfli-carrid

    spfli-connid

    spfli-countryfr

    spfli-cityfrom

    spfli-airpfrom

    spfli-countryto

    spfli-cityto

    spfli-airpto

    w_fltime

    spfli-deptime

    spfli-arrtime

    w_distance

    spfli-distid

    spfli-fltype

    w_period

    INTO w_tempstring SEPARATED BY con_tab.

    CONCATENATE w_string w_tempstring con_cret INTO w_string.

    AT LAST.

    DATA: lw_string LIKE w_tempstring.

    CONCATENATE 'saibaba kondani' 'temp'

    INTO lw_string SEPARATED BY con_tab.

    CONCATENATE w_string w_tempstring con_cret INTO w_string.

    ENDAT.

    ENDLOOP.

    • Converting the above String to the Internal table of FM

    CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

    EXPORTING

    text = w_string

    • IMPORTING

    • LENGTH = LENGTH

    TABLES

    ftext_tab = data_tab.

    • This is the Data of Attachment

    objbin[] = data_tab.

    DESCRIBE TABLE objbin LINES w_tablines.

    • This is the name of Attachment

    • If the Attachment type is text then name should be given with

    • '.TXT' extension and for Excel attachment '.XLS' extension

    • should be given.

    objhead = 'SPFLI.XLS'.

    APPEND objhead.

    • Creating the entry for the compressed attachment

    • These are the details for the Attachemnt

    objpack-transf_bin = 'X'.

    objpack-head_start = 1.

    objpack-head_num = 1.

    objpack-body_start = 1.

    objpack-body_num = w_tablines.

    • This is the Attachment type(For excel 'XLS' and fot text 'TXT' should

    objpack-doc_type = 'XLS'.

    objpack-obj_name = 'DATA_ATTACHMENT'.

    objpack-obj_descr = 'Spfli attachment table'.

    objpack-doc_size = w_tablines * 255.

    APPEND objpack.

    • Entering names in the distribution list( These are the receivers )

    reclist-receiver = mailid.

    reclist-rec_type = 'U'.

    • RECLIST-NOTIF_READ = 'X'.

    APPEND reclist.

    REFRESH data_tab.

    CLEAR data_tab.

    CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

    EXPORTING

    text = lw_string

    • IMPORTING

    • LENGTH = LENGTH

    TABLES

    ftext_tab = data_tab.

    DESCRIBE TABLE objbin LINES w_tablines.

    • Creating the entry for the compressed attachment

    • These are the details for the Attachemnt

    objpack-transf_bin = 'X'.

    objpack-head_start = w_tablines + 1.

    objpack-head_num = 0.

    objpack-body_start = w_tablines + 1.

    objpack-body_num = w_tablines.

    • This is the Attachment type(For excel 'XLS' and fot text 'TXT' should

    objpack-doc_type = 'XLS'.

    objpack-obj_name = 'DATA_ATTACHMENT'.

    objpack-obj_descr = 'Spfli attachment table'.

    objpack-doc_size = w_tablines * 255.

    APPEND objpack.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = doc_chng

    put_in_outbox = 'X'

    commit_work = 'X'

    IMPORTING

    sent_to_all = sent_to_all

    new_object_id = new_object_id

    TABLES

    packing_list = objpack

    object_header = objhead

    contents_bin = objbin

    contents_txt = objtxt

    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.

    IF sy-subrc EQ 0.

    WRITE : / sent_to_all,new_object_id.

    ENDIF.

    • This Program is used to Trigger the send process Explicitely

    WAIT UP TO 2 SECONDS.

    SUBMIT rsconn01 WITH mode = 'INT'

    WITH output = 'X'

    AND RETURN.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 01:54 PM

    data: p_email type somlreci1-receiver

    value 'sdabap@XXX'.

    data: begin of it001 occurs 0,

    bukrs type t001-bukrs,

    butxt type t001-butxt,

    end of it001.

    data: imessage type standard table of solisti1 with header line,

    iattach type standard table of solisti1 with header line,

    ipacking_list like sopcklsti1 occurs 0 with header line,

    ireceivers like somlreci1 occurs 0 with header line,

    iattachment like solisti1 occurs 0 with header line.

    start-of-selection.

    select bukrs butxt into table it001 from t001.

    • Populate table with detaisl to be entered into .xls file

    perform build_xls_data .

    • Populate message body text

    clear imessage. refresh imessage.

    imessage = 'Please find attached excel file'.

    append imessage.

    • Send file by email as .xls speadsheet

    perform send_email_with_xls tables imessage

    iattach

    using p_email

    'Example Excel Attachment'

    'XLS'

    'TestFileName'

    'CompanyCodes'.

    ************************************************************************

    • Form BUILD_XLS_DATA

    ************************************************************************

    form build_xls_data .

    • constants: con_cret type x value '0D', "OK for non Unicode

    • con_tab type x value '09'. "OK for non Unicode

    *If you have Unicode check active in program attributes thnen you will

    *need to declare constants as follows

    *class cl_abap_char_utilities definition load.

    constants:

    con_tab type c value cl_abap_char_utilities=>horizontal_tab,

    con_cret type c value cl_abap_char_utilities=>cr_lf.

    concatenate 'BUKRS' 'BUTXT'

    into iattach separated by con_tab.

    concatenate con_cret iattach into iattach.

    append iattach.

    loop at it001 .

    concatenate it001-bukrs it001-butxt

    into iattach separated by con_tab.

    concatenate con_cret iattach into iattach.

    append iattach.

    endloop .

    endform.

    ************************************************************************

    • Form SEND_EMAIL_WITH_XLS

    ************************************************************************

    form send_email_with_xls tables pit_message

    pit_attach

    using p_email

    p_mtitle

    p_format

    p_filename

    p_attdescription.

    data: xdocdata like sodocchgi1,

    xcnt type i.

    • Fill the document data.

    xdocdata-doc_size = 1.

    • Populate the subject/generic message attributes

    xdocdata-obj_langu = sy-langu .

    xdocdata-obj_name = 'SAPRPT' .

    xdocdata-obj_descr = p_mtitle .

    • Fill the document data and get size of attachment

    clear xdocdata.

    read table iattach index xcnt.

    xdocdata-doc_size =

    ( xcnt - 1 ) * 255 + strlen( iattach ).

    xdocdata-obj_langu = sy-langu.

    xdocdata-obj_name = 'SAPRPT'.

    xdocdata-obj_descr = p_mtitle.

    clear iattachment. refresh iattachment.

    iattachment[] = pit_attach[].

    • Describe the body of the message

    clear ipacking_list. refresh ipacking_list.

    ipacking_list-transf_bin = space.

    ipacking_list-head_start = 1.

    ipacking_list-head_num = 0.

    ipacking_list-body_start = 1.

    describe table imessage lines ipacking_list-body_num.

    ipacking_list-doc_type = 'RAW'.

    append ipacking_list.

    • Create attachment notification

    ipacking_list-transf_bin = 'X'.

    ipacking_list-head_start = 1.

    ipacking_list-head_num = 1.

    ipacking_list-body_start = 1.

    describe table iattachment lines ipacking_list-body_num.

    ipacking_list-doc_type = p_format.

    ipacking_list-obj_descr = p_attdescription.

    ipacking_list-obj_name = p_filename.

    ipacking_list-doc_size = ipacking_list-body_num * 255.

    append ipacking_list.

    • Add the recipients email address

    clear ireceivers. refresh ireceivers.

    ireceivers-receiver = p_email.

    ireceivers-rec_type = 'U'.

    ireceivers-com_type = 'INT'.

    ireceivers-notif_del = 'X'.

    ireceivers-notif_ndel = 'X'.

    append ireceivers.

    call function 'SO_DOCUMENT_SEND_API1'

    exporting

    document_data = xdocdata

    put_in_outbox = 'X'

    commit_work = 'X'

    tables

    packing_list = ipacking_list

    contents_bin = iattachment

    contents_txt = imessage

    receivers = ireceivers

    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.

    endform.

    Plz Search before posting the que................

    Reward IF.....................

    regards

    Anbu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:10 PM

    check this fm:

    FUNCTION Z_SEND_MAIL_FOR_SPOOLLIST.

    *"----


    ""Local interface:

    *" IMPORTING

    *" REFERENCE(SPOOLNUMBER) LIKE SY-SPONO DEFAULT SY-SPONO

    *" REFERENCE(MAILNAME) LIKE SOOD1-OBJNAM DEFAULT 'NOTE'

    *" REFERENCE(SUBJECT) LIKE SOOD1-OBJDES

    *" REFERENCE(RECEPIENT) LIKE SY-UNAME DEFAULT SY-UNAME

    *" REFERENCE(DLI) LIKE SOOS1-DLINAM OPTIONAL

    *" TABLES

    *" TEXT STRUCTURE SOLI

    *" EXCEPTIONS

    *" ERROR

    *"----


    DATA: OBJECT_HD_CHANGE LIKE SOOD1 OCCURS 0 WITH HEADER LINE,

    OBJPARA LIKE SELC OCCURS 0 WITH HEADER LINE,

    RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE.

    OBJECT_HD_CHANGE-OBJLA = SY-LANGU.

    OBJECT_HD_CHANGE-OBJNAM = MAILNAME.

    OBJECT_HD_CHANGE-OBJDES = SUBJECT.

    OBJECT_HD_CHANGE-OBJSNS = 'F'.

    OBJECT_HD_CHANGE-VMTYP = 'T'.

    OBJECT_HD_CHANGE-SKIPS = 'X'.

    OBJECT_HD_CHANGE-ACNAM = 'SP01'.

    OBJECT_HD_CHANGE-OBJCP = 'X'.

    OBJECT_HD_CHANGE-OBJPRI = '1'.

    *OBJECT_HD_CHANGE-ACOUT = 'X'.

    RECEIVERS-RCDAT = SY-DATUM.

    RECEIVERS-RCTIM = SY-UZEIT.

    IF DLI IS INITIAL.

    RECEIVERS-RECNAM = RECEPIENT.

    RECEIVERS-RTUNAM = RECEPIENT.

    ELSE.

    RECEIVERS-RECNAM = DLI.

    RECEIVERS-ADR_NAME = DLI.

    RECEIVERS-RECESC = 'C'.

    ENDIF.

    RECEIVERS-SNDEX = 'X'. " Express-Mail

    *RECEIVERS-SNDPRI = 'X'.

    move 'B' TO RECEIVERS-RECESC.

    move '1' TO RECEIVERS-ACONE.

    RECEIVERS-DELIVER = 'X'.

    *RECEIVERS-NOT_DELI = 'X'.

    RECEIVERS-READ = 'X'.

    RECEIVERS-MAILSTATUS = 'E'.

    APPEND RECEIVERS.

    OBJPARA-NAME = 'SPI'.

    OBJPARA-LOW = SPOOLNUMBER.

    APPEND OBJPARA.

    CALL FUNCTION 'SO_OBJECT_SEND'

    EXPORTING

    OBJECT_HD_CHANGE = OBJECT_HD_CHANGE

    OBJECT_TYPE = 'RAW'

    OWNER = SY-UNAME

    TABLES

    OBJCONT = TEXT

    OBJPARA = OBJPARA

    RECEIVERS = RECEIVERS

    EXCEPTIONS

    OTHERS = 01.

    IF SY-SUBRC NE 0.

    • RAISE ERROR.

    ENDIF.

    COMMIT WORK.

    CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.

    ENDFUNCTION.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:12 PM

    we have unix and sendmail activated, if you have it you can do it also. Check this:

    If you use UNIX in your server then you can use this system function:

    call 'SYSTEM' id 'COMMAND' field

    id 'TAB' field result-sys.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:15 PM

    check this:

    http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm

    and this example:

    The code below demonstrates how to send an email to an external email address

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    *& Report ZSENDEMAIL *

    *& *

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    *& Example of sending external email via SAPCONNECT *

    *& *

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    REPORT zsendemail .

    PARAMETERS: psubject(40) type c default u2018Hellou2019,

    p_email(40) type c default u2018your mail hereu2019 .

    data: it_packing_list like sopcklsti1 occurs 0 with header line,

    it_contents like solisti1 occurs 0 with header line,

    it_receivers like somlreci1 occurs 0 with header line,

    it_attachment like solisti1 occurs 0 with header line,

    gd_cnt type i,

    gd_sent_all(1) type c,

    gd_doc_data like sodocchgi1,

    gd_error type sy-subrc.

    data: it_message type standard table of SOLISTI1 initial size 0

    with header line.

    ***********************************************************************

    *START-OF-SELECTION.

    START-OF-SELECTION.

    Perform populate_message_table.

    *Send email message, although is not sent from SAP until mail send

    *program has been executed(rsconn01)

    PERFORM send_email_message.

    *Instructs mail send program for SAPCONNECT to send email(rsconn01)

    perform initiate_mail_execute_program.

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    *& Form POPULATE_MESSAGE_TABLE

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    • Adds text to email text table

    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

    form populate_message_table.

    Append u2018Email line 1u2032 to it_message.

    Append u2018Email line 2u2032 to it_message.

    Append u2018Email line 3u2032 to it_message.

    Append u2018Email line 4u2032 to it_message.

    endform. u201D POPULATE_MESSAGE_TABLE

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    *& Form SEND_EMAIL_MESSAGE

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    • Send email message

    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

    form send_email_message.

    • Fill the document data.

    gd_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    gd_doc_data-obj_langu = sy-langu.

    gd_doc_data-obj_name = u2018SAPRPTu2019.

    gd_doc_data-obj_descr = psubject.

    gd_doc_data-sensitivty = u2018Fu2019.

    • Describe the body of the message

    clear it_packing_list.

    refresh it_packing_list.

    it_packing_list-transf_bin = space.

    it_packing_list-head_start = 1.

    it_packing_list-head_num = 0.

    it_packing_list-body_start = 1.

    describe table it_message lines it_packing_list-body_num.

    it_packing_list-doc_type = u2018RAWu2019.

    append it_packing_list.

    • Add the recipients email address

    clear it_receivers.

    refresh it_receivers.

    it_receivers-receiver = p_email.

    it_receivers-rec_type = u2018Uu2019.

    it_receivers-com_type = u2018INTu2019.

    it_receivers-notif_del = u2018Xu2019.

    it_receivers-notif_ndel = u2018Xu2019.

    append it_receivers.

    • Call the FM to post the message to SAPMAIL

    call function u2018SO_NEW_DOCUMENT_ATT_SEND_API1u2032

    exporting

    document_data = gd_doc_data

    put_in_outbox = u2018Xu2019

    importing

    sent_to_all = gd_sent_all

    tables

    packing_list = it_packing_list

    contents_txt = it_message

    receivers = it_receivers

    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.

    • Store function module return code

    gd_error = sy-subrc.

    • Get it_receivers return code

    loop at it_receivers.

    endloop.

    endform. u201D SEND_EMAIL_MESSAGE

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    *& Form INITIATE_MAIL_EXECUTE_PROGRAM

    &u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

    • Instructs mail send program for SAPCONNECT to send email.

    u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

    form initiate_mail_execute_program.

    wait up to 2 seconds.

    if gd_error eq 0.

    submit rsconn01 with mode = u2018INTu2019

    with output = u2018Xu2019

    and return.

    endif.

    endform. u201D INITIATE_MAIL_EXECUTE_PROGRAM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.