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

function to send e-mail

Hi guys,

somebody could tell me which is the function to send e-mail in abap program?... have an example with this functions?

Thanks in advance.

regards.

Marisol

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 10:14 PM

    How to send a report to an external mail-id?

    Try this sample code :-

    REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.

    DATA : BEGIN OF ITAB OCCURS 0,

    PERNR LIKE PA0001-PERNR,

    ENAME LIKE PA0001-ENAME,

    END OF ITAB.

    DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

    receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

    packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

    listobject LIKE abaplist OCCURS 10,

    compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

    w_object_hd_change LIKE sood1,

    compressed_size LIKE sy-index.

    START-OF-SELECTION.

    SELECT PERNR ENAME

    INTO CORRESPONDING FIELDS OF TABLE ITAB

    FROM PA0001

    WHERE PERNR < 50.

    LOOP AT ITAB.

    WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50

    SY-VLINE.

    ENDLOOP.

    • Receivers

    receiver_list-recextnam = 'EXTERNAL-MAIL-ID@YAHOO.COM'. "-->

    • EMAIL ADDRESS

    RECEIVER_list-RECESC = 'E'. "<-

    RECEIVER_list-SNDART = 'INT'."<-

    RECEIVER_list-SNDPRI = '1'."<-

    APPEND receiver_list.

    • General data

    w_object_hd_change-objla = sy-langu.

    w_object_hd_change-objnam = 'Object name'.

    w_object_hd_change-objsns = 'P'.

    • Mail subject

    w_object_hd_change-objdes = 'Message subject'.

    • Mail body

    APPEND 'Message content' TO message_content.

    • Attachment

    CALL FUNCTION 'SAVE_LIST'

    EXPORTING

    list_index = '0'

    TABLES

    listobject = listobject.

    CALL FUNCTION 'TABLE_COMPRESS'

    IMPORTING

    compressed_size = compressed_size

    TABLES

    in = listobject

    out = compressed_attachment.

    DESCRIBE TABLE compressed_attachment.

    CLEAR packing_list.

    packing_list-transf_bin = 'X'.

    packing_list-head_start = 0.

    packing_list-head_num = 0.

    packing_list-body_start = 1.

    packing_list-body_num = sy-tfill.

    packing_list-objtp = 'ALI'.

    packing_list-objnam = 'Object name'.

    packing_list-objdes = 'Attachment description'.

    packing_list-objlen = compressed_size.

    APPEND packing_list.

    CALL FUNCTION 'SO_OBJECT_SEND'

    EXPORTING

    object_hd_change = w_object_hd_change

    object_type = 'RAW'

    owner = sy-uname

    TABLES

    objcont = message_content

    receivers = receiver_list

    packing_list = packing_list

    att_cont = compressed_attachment.

    Regards,

    Satya

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 08, 2008 at 04:37 AM

    hi,

    check this,

    for sending mail in pdf

    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 04:40 AM

    Hi,

    Please go through the piece of code:

    REPORT ZSEND .

    TABLES: KNA1.

    • data for send function

    DATA DOC_DATA LIKE SODOCCHGI1.

    DATA OBJECT_ID LIKE SOODK.

    DATA OBJCONT LIKE SOLI OCCURS 10 WITH HEADER LINE.

    DATA RECEIVER LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.

    SELECT * FROM KNA1 WHERE ANRED LIKE 'C%'.

    WRITE:/ KNA1-KUNNR, KNA1-ANRED.

    • send data internal table

    CONCATENATE KNA1-KUNNR KNA1-ANRED

    INTO OBJCONT-LINE SEPARATED BY SPACE.

    APPEND OBJCONT.

    ENDSELECT.

    • insert receiver (sap name)

    REFRESH RECEIVER.

    CLEAR RECEIVER.

    MOVE: SY-UNAME TO RECEIVER-RECEIVER,

    'X' TO RECEIVER-EXPRESS,

    'B' TO RECEIVER-REC_TYPE.

    APPEND RECEIVER.

    • insert mail description

    WRITE 'Sending a mail through abap'

    TO DOC_DATA-OBJ_DESCR.

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = DOC_DATA

    IMPORTING

    NEW_OBJECT_ID = OBJECT_ID

    TABLES

    OBJECT_CONTENT = OBJCONT

    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.

    Thnaks,

    Sandeep.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 04:53 AM

    Hi Marisol,

    Try this code.

    LOOP AT t_mail.

    CLEAR l_subj.

    CLEAR doc_chng.

    CLEAR reclist_str.

    IF t_mail-usrid IS NOT INITIAL.

    • Subject line of the mail---------------------------------------*

    l_subj = 'Log for the Reminder Call Letter'.

    doc_chng-obj_descr = l_subj.

    doc_chng-sensitivty = 'P'.

    doc_chng-proc_syst = sy-sysid.

    doc_chng-proc_clint = sy-mandt.

    doc_chng-proc_type = 'R'.

    reclist_str-receiver = t_mail-usrid.

    reclist_str-rec_type = 'U'.

    APPEND reclist_str TO reclist.

    CLEAR reclist_str.

    • Call function to send mail to officers-------------------------*

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = doc_chng

    put_in_outbox = 'X'

    commit_work = 'X'

    TABLES

    object_content = t_mail_txt

    receivers = reclist

    EXCEPTIONS

    too_many_receivers = 1

    document_not_sent = 2

    operation_no_authorization = 4

    OTHERS = 99.

    IF sy-subrc EQ 0.

    COMMIT WORK.

    ENDIF.

    CLEAR reclist.

    REFRESH reclist.

    CLEAR t_mail.

    ENDIF.

    ENDLOOP.

    If it is helpfull pls do reward pts

    Regards

    Srimanta

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 06:23 AM

    Hi Marisol,

    "ZSENDEMAIL" Use this function module to

    send the email in u r ABAP program.

    According to u r requirement it will help you.

    If u get any queries while using this fnmodule

    post the query.

    Regards

    AshokChowdhary

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 10:00 PM

    Try SO_NEW_DOCUMENT_ATT_SEND_API1

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 06:04 AM

    Hi , this will help u.

    How to send a report to an external mail-id?

    Try this sample code :-

    REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.

    DATA : BEGIN OF ITAB OCCURS 0,

    PERNR LIKE PA0001-PERNR,

    ENAME LIKE PA0001-ENAME,

    END OF ITAB.

    DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

    receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

    packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

    listobject LIKE abaplist OCCURS 10,

    compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

    w_object_hd_change LIKE sood1,

    compressed_size LIKE sy-index.

    START-OF-SELECTION.

    SELECT PERNR ENAME

    INTO CORRESPONDING FIELDS OF TABLE ITAB

    FROM PA0001

    WHERE PERNR < 50.

    LOOP AT ITAB.

    WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50

    SY-VLINE.

    ENDLOOP.

    Receivers

    receiver_list-recextnam = 'EXTERNAL-MAIL-ID@YAHOO.COM'. "-->

    EMAIL ADDRESS

    RECEIVER_list-RECESC = 'E'. "<-

    RECEIVER_list-SNDART = 'INT'."<-

    RECEIVER_list-SNDPRI = '1'."<-

    APPEND receiver_list.

    General data

    w_object_hd_change-objla = sy-langu.

    w_object_hd_change-objnam = 'Object name'.

    w_object_hd_change-objsns = 'P'.

    Mail subject

    w_object_hd_change-objdes = 'Message subject'.

    Mail body

    APPEND 'Message content' TO message_content.

    Attachment

    CALL FUNCTION 'SAVE_LIST'

    EXPORTING

    list_index = '0'

    TABLES

    listobject = listobject.

    CALL FUNCTION 'TABLE_COMPRESS'

    IMPORTING

    compressed_size = compressed_size

    TABLES

    in = listobject

    out = compressed_attachment.

    DESCRIBE TABLE compressed_attachment.

    CLEAR packing_list.

    packing_list-transf_bin = 'X'.

    packing_list-head_start = 0.

    packing_list-head_num = 0.

    packing_list-body_start = 1.

    packing_list-body_num = sy-tfill.

    packing_list-objtp = 'ALI'.

    packing_list-objnam = 'Object name'.

    packing_list-objdes = 'Attachment description'.

    packing_list-objlen = compressed_size.

    APPEND packing_list.

    CALL FUNCTION 'SO_OBJECT_SEND'

    EXPORTING

    object_hd_change = w_object_hd_change

    object_type = 'RAW'

    owner = sy-uname

    TABLES

    objcont = message_content

    receivers = receiver_list

    packing_list = packing_list

    att_cont = compressed_attachment

    with regards,

    Hema.

    pls reward if helpful.

    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.