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

Standard Function module for sending mails?

Hi Experts,

Is there an existing function module to send mails?

I do not want to hardcode the mail ID of the recipient instead pass it as an import parameter.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 04:15 AM

    hi,

    U can use FM "SO_NEW_DOCUMENT_SEND_API1" .

    U can declare the email ids in a constt table and pass those values in the FM.

    Pls reward if useful

    Regards,

    Preeti

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 04:15 AM

    Hi,

    SO_NEW_DOCUMENT_ATT_SEND_API1

    regards,

    Santosh Thorat

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 04:16 AM

    Function Modules :

    HR_FBN_GENERATE_SEND_EMAIL Generate and send E-Mail

    HR_FBN_GET_USER_EMAIL_ADDRESS Get the email address according to SAP user ID

    Reward Points if useful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 04:20 AM

    hi

    good

    go through this link this will give you complete idea about sending mails in sap.

    http://www.thespot4sap.com/Articles/SAP_Mail_Understanding_SO_Object_Send.asp

    thanks

    mrutyun^

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 27, 2007 at 04:28 AM

    Hi Sunitha,

    U can use FM "SO_NEW_DOCUMENT_SEND_API1" . for sending the mail.

    Or you can either use the class for sending the mail.

    Here i am sending example of both using the FM and Class.

    Please check it. It might help you.

    Example using FM

    • Internal Table declarations

    DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

    I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

    I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

    I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    • Objects to send mail.

    I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

    I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

    • Work Area declarations

    WA_OBJHEAD TYPE SOLI_TAB,

    W_CTRLOP TYPE SSFCTRLOP,

    W_COMPOP TYPE SSFCOMPOP,

    W_RETURN TYPE SSFCRESCL,

    WA_DOC_CHNG TYPE SODOCCHGI1,

    W_DATA TYPE SODOCCHGI1,

    WA_BUFFER TYPE STRING, "To convert from 132 to 255

    • Variables declarations

    V_FORM_NAME TYPE RS38L_FNAM,

    V_LEN_IN LIKE SOOD-OBJLEN,

    V_LEN_OUT LIKE SOOD-OBJLEN,

    V_LEN_OUTN TYPE I,

    V_LINES_TXT TYPE I,

    V_LINES_BIN TYPE I.

    TABLES: SCUSTOM, SBOOK, SPFLI.

    SELECT-OPTIONS: S_ID FOR SCUSTOM-ID DEFAULT 1 TO 1,

    S_FLI FOR SBOOK-CARRID DEFAULT 'LH' TO 'LH'.

    DATA CUSTOMERS LIKE SCUSTOM OCCURS 100

    WITH HEADER LINE.

    DATA BOOKINGS LIKE SBOOK OCCURS 1000

    WITH HEADER LINE.

    DATA CONNECTIONS LIKE SPFLI OCCURS 1000

    WITH HEADER LINE.

    DATA: BEGIN OF SUMS OCCURS 10,

    FORCURAM LIKE SBOOK-FORCURAM,

    FORCURKEY LIKE SBOOK-FORCURKEY,

    END OF SUMS.

    *DATA : FM_NAME TYPE RS38L_FNAM.

    • Get data

    SELECT * FROM SCUSTOM INTO TABLE CUSTOMERS

    WHERE ID IN S_ID

    ORDER BY PRIMARY KEY.

    SELECT * FROM SBOOK INTO TABLE BOOKINGS

    WHERE CUSTOMID IN S_ID AND CARRID IN S_FLI

    ORDER BY PRIMARY KEY.

    SELECT * FROM SPFLI INTO TABLE CONNECTIONS

    FOR ALL ENTRIES IN BOOKINGS

    WHERE CARRID = BOOKINGS-CARRID

    AND CONNID = BOOKINGS-CONNID

    ORDER BY PRIMARY KEY.

    *CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    *EXPORTING

    *FORMNAME = 'ZMAN_FLIGHTFORMCOPY'

    *IMPORTING

    *FM_NAME = V_FORM_NAME

    *EXCEPTIONS

    *NO_FORM = 1

    *NO_FUNCTION_MODULE = 2

    *OTHERS = 3.

    *IF SY-SUBRC <> 0.

    *MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    *WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    *ENDIF.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = 'ZMAN_FLIGHTFORMCOPY'

    • VARIANT = ' '

    • DIRECT_CALL = ' '

    IMPORTING

    FM_NAME = V_FORM_NAME

    • EXCEPTIONS

    • NO_FORM = 1

    • NO_FUNCTION_MODULE = 2

    • OTHERS = 3

    .

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    W_CTRLOP-GETOTF = 'X'.

    W_CTRLOP-NO_DIALOG = 'X'.

    W_COMPOP-TDNOPREV = 'X'.

    CALL FUNCTION V_FORM_NAME

    EXPORTING

    CONTROL_PARAMETERS = W_CTRLOP

    OUTPUT_OPTIONS = W_COMPOP

    USER_SETTINGS = 'X'

    IMPORTING

    JOB_OUTPUT_INFO = W_RETURN

    TABLES

    IT_ITAB = CUSTOMERS

    IT_ITAB1 = BOOKINGS

    IT_ITAB2 = CONNECTIONS

    IT_TEMP = BOOKINGS

    EXCEPTIONS

    FORMATTING_ERROR = 1

    INTERNAL_ERROR = 2

    SEND_ERROR = 3

    USER_CANCELED = 4

    OTHERS = 5

    .

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    *EXPORTING

    *CONTROL_PARAMETERS = W_CTRLOP

    *OUTPUT_OPTIONS = W_COMPOP

    *USER_SETTINGS = 'X'

    *IMPORTING

    *JOB_OUTPUT_INFO = W_RETURN

    *EXCEPTIONS

    *FORMATTING_ERROR = 1

    *INTERNAL_ERROR = 2

    *SEND_ERROR = 3

    *USER_CANCELED = 4

    *OTHERS = 5.

    *IF SY-SUBRC <> 0.

    *MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    *WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    *ENDIF.

    I_OTF[] = W_RETURN-OTFDATA[].

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    MAX_LINEWIDTH = 132

    IMPORTING

    BIN_FILESIZE = V_LEN_IN

    TABLES

    OTF = I_OTF

    LINES = I_TLINE

    EXCEPTIONS

    ERR_MAX_LINEWIDTH = 1

    ERR_FORMAT = 2

    ERR_CONV_NOT_POSSIBLE = 3

    OTHERS = 4.

    IF SY-SUBRC <> 0.

    ENDIF.

    LOOP AT I_TLINE.

    TRANSLATE I_TLINE USING '~'.

    CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

    ENDLOOP.

    TRANSLATE WA_BUFFER USING '~'.

    DO.

    I_RECORD = WA_BUFFER.

    APPEND I_RECORD.

    SHIFT WA_BUFFER LEFT BY 255 PLACES.

    IF WA_BUFFER IS INITIAL.

    EXIT.

    ENDIF.

    ENDDO.

    • Attachment

    REFRESH: I_RECLIST,

    I_OBJTXT,

    I_OBJBIN,

    I_OBJPACK.

    CLEAR WA_OBJHEAD.

    I_OBJBIN[] = I_RECORD[].

    • Create Message Body Title and Description

    I_OBJTXT = 'test with pdf-Attachment!'.

    APPEND I_OBJTXT.

    DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

    READ TABLE I_OBJTXT INDEX V_LINES_TXT.

    WA_DOC_CHNG-OBJ_NAME = 'smartform'.

    WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

    WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

    WA_DOC_CHNG-SENSITIVTY = 'F'.

    WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

    • Main Text

    CLEAR I_OBJPACK-TRANSF_BIN.

    I_OBJPACK-HEAD_START = 1.

    I_OBJPACK-HEAD_NUM = 0.

    I_OBJPACK-BODY_START = 1.

    I_OBJPACK-BODY_NUM = V_LINES_TXT.

    I_OBJPACK-DOC_TYPE = 'RAW'.

    APPEND I_OBJPACK.

    • Attachment (pdf-Attachment)

    I_OBJPACK-TRANSF_BIN = 'X'.

    I_OBJPACK-HEAD_START = 1.

    I_OBJPACK-HEAD_NUM = 0.

    I_OBJPACK-BODY_START = 1.

    DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

    READ TABLE I_OBJBIN INDEX V_LINES_BIN.

    I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

    I_OBJPACK-BODY_NUM = V_LINES_BIN.

    I_OBJPACK-DOC_TYPE = 'PDF'.

    I_OBJPACK-OBJ_NAME = 'smart'.

    I_OBJPACK-OBJ_DESCR = 'test'.

    APPEND I_OBJPACK.

    CLEAR I_RECLIST.

    I_RECLIST-RECEIVER = 'abc@yahoo.com'.

    I_RECLIST-REC_TYPE = 'U'.

    APPEND I_RECLIST.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = WA_DOC_CHNG

    PUT_IN_OUTBOX = 'X'

    COMMIT_WORK = 'X'

    TABLES

    PACKING_LIST = I_OBJPACK

    OBJECT_HEADER = WA_OBJHEAD

    CONTENTS_BIN = I_OBJBIN

    CONTENTS_TXT = I_OBJTXT

    RECEIVERS = I_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.

    IF SY-SUBRC <> 0.

    WRITE:/ 'Error When Sending the File', SY-SUBRC.

    ELSE.

    WRITE:/ 'Mail sent'.

    ENDIF.

    Example using Class - cl_bcs

    FORM send_mail TABLES p_it_error_records LIKE it_error_records p_it_parked_documents LIKE it_success_records USING p_count TYPE string p_text TYPE string.

    DATA: send_request TYPE REF TO cl_bcs,

    att_text TYPE bcsy_text, "#EC NEEDED

    document TYPE REF TO cl_document_bcs, "#EC NEEDED

    sender TYPE REF TO cl_sapuser_bcs, "#EC NEEDED

    recipient TYPE REF TO if_recipient_bcs,

    bcs_exception TYPE REF TO cx_bcs,

    sent_to_all TYPE os_boolean,

    v_str(255) TYPE c,

    wa_receivers TYPE adr6,

    wa_text TYPE bcsy_text,

    v_subject TYPE so_obj_des.

    DATA:it_receivers TYPE TABLE OF adr6.

    wa_receivers-smtp_addr = 'abc@yahoo.com'.

    APPEND wa_receivers TO it_receivers.

    CLEAR wa_receivers.

    wa_receivers-smtp_addr = 'xyz@yahoo.com'.

    APPEND wa_receivers TO it_receivers.

    CLEAR:wa_receivers,

    wa_bdcmsgcoll.

    • wa_receivers-smtp_addr = 'pqr@yahoo.com'.

    • APPEND wa_receivers TO it_receivers.

    • CLEAR wa_receivers.

    CONCATENATE text-004 sy-datum INTO v_subject SEPARATED BY space.

    TRY.

    ----


    create persistent send request -

    send_request = cl_bcs=>create_persistent( ).

    ----


    create and set document with attachment -

    • create document from internal table with text

    document = cl_document_bcs=>create_document(

    i_type = 'RAW'

    i_text = wa_text

    i_length = '60'

    i_subject = v_subject ).

    --


    add attachment to document--

    REFRESH wa_text.

    CONCATENATE p_count p_text INTO v_str.

    APPEND v_str TO wa_text.

    LOOP AT p_it_parked_documents INTO wa_bdcmsgcoll1 . " For Success Records

    AT FIRST.

    MOVE text-016 TO v_str.

    APPEND v_str TO wa_text.

    CLEAR v_str.

    ENDAT.

    CONCATENATE wa_bdcmsgcoll1-msgv3 wa_bdcmsgcoll1-msgtyp wa_bdcmsgcoll1-msgnr

    wa_bdcmsgcoll1-msgv2 wa_bdcmsgcoll1-msgv1 text-014 INTO v_str SEPARATED BY space.

    APPEND v_str TO wa_text.

    ENDLOOP.

    LOOP AT p_it_error_records INTO wa_bdcmsgcoll1 . "For Error Records

    AT FIRST.

    MOVE text-015 TO v_str.

    APPEND v_str TO wa_text.

    ENDAT.

    CONCATENATE wa_bdcmsgcoll1-msgv3 wa_bdcmsgcoll1-msgtyp wa_bdcmsgcoll1-msgnr wa_bdcmsgcoll1-msgv2

    wa_bdcmsgcoll1-msgv1 wa_bdcmsgcoll1-msgv4 INTO v_str SEPARATED BY space.

    APPEND v_str TO wa_text.

    ENDLOOP.

    CALL METHOD document->add_attachment "Adding Attachment

    EXPORTING

    i_attachment_type = 'RAW'

    i_attachment_subject = v_subject

    i_attachment_size = '60'

    i_att_content_text = wa_text.

    • add document to send request

    CALL METHOD send_request->set_document( document ).

    LOOP AT it_receivers INTO wa_receivers . "Recievers SMTP address

    recipient =

    cl_cam_address_bcs=>create_internet_address( wa_receivers-smtp_addr ).

    ----


    add recipient with its respective attributes to send request-

    CALL METHOD send_request->add_recipient

    EXPORTING

    i_recipient = recipient

    i_express = 'X'.

    ENDLOOP.

    ----


    send document -

    CALL METHOD send_request->send(

    EXPORTING

    i_with_error_screen = 'X'

    RECEIVING

    result = sent_to_all ).

    IF sent_to_all = 'X'.

    MESSAGE text-010 TYPE 'S'. " Document Sent Successfully

    ENDIF.

    COMMIT WORK.

    • -----------------------------------------------------------

    • * exception handling

    • -----------------------------------------------------------

    • -----------------------------------------------------------

    CATCH cx_bcs INTO bcs_exception. " Exception while sending mail

    WRITE: text-009 , bcs_exception->error_type.

    EXIT.

    ENDTRY.

    ENDFORM. "seding_mail

    Reward Points, if useful.

    Regards,

    Manoj Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 04:31 AM

    Hi,

    Please refer to the link below :

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

    Thanks,

    Sriram Ponna.

    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.