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

Email trigger thru SAP

Hi,

I have got a code from one of the forums topics on how to trigger mails from SAP to outlook express inbox.

Well but when i am trying to execute the code,the code is throwing an exception "Document not sent" .

I runa report program for DMS where i have data for different types of Doc's in an internal table.

Now i want to send e-mails according to Doc type.Please help find the solution to the problem.

Manually if i try send the mail thru SCOT T-code,its working so guess my all configuration is okay .

I am also attaching the sample code for reference.

TABLES : DRAW.

DATA : ITAB_DRAW LIKE DRAW OCCURS 0 WITH HEADER LINE .

data : date type sy-datum.

data: itcpo like itcpo,

tab_lines like sy-tabix.

  • Variables for EMAIL functionality

data: maildata like sodocchgi1.

data: mailpack like sopcklsti1 occurs 2 with header line.

data: mailhead like solisti1 occurs 1 with header line.

data: mailbin like solisti1 occurs 10 with header line.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: solisti1 like solisti1 occurs 0 with header line.

perform send_form_via_email.

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

  • FORM SEND_FORM_VIA_EMAIL *

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

form send_form_via_email.

clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

maildata-obj_descr = 'ALERT : DOC GETTING EXPIRED'.

  • Mail Contents

mailtxt-line = 'Please find the attached file'.

append mailtxt.

  • Prepare Packing List

perform prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = 'dsm-ltil@essar.com'.

mailrec-rec_type = 'U'.

append mailrec.

date = sy-datum + 1 .

SELECT * FROM DRAW INTO TABLE ITAB_DRAW

WHERE VRLDAT = date.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = maildata

put_in_outbox = ' '

tables

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

endform.

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

  • Form PREPARE_PACKING_LIST

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

form prepare_packing_list.

clear: mailpack, mailbin, mailhead.

refresh: mailpack, mailbin, mailhead.

describe table mailtxt lines tab_lines.

read table mailtxt index tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

  • Creation of the entry for the compressed document

clear mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

append mailpack.

mailhead = 'TEST.TXT'.

append mailhead.

  • File 1

mailbin = 'This is file 1'.

append mailbin.

describe table mailbin lines tab_lines.

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'TXT'.

mailpack-obj_name = 'TEST1'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

append mailpack.

*File 2

mailbin = 'This is file 2'.

append mailbin.

data: start type i.

data: end type i.

start = tab_lines + 1.

describe table mailbin lines end.

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = start.

mailpack-body_num = end.

mailpack-doc_type = 'TXT'.

mailpack-obj_name = 'TEST2'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

append mailpack.

endform.

Also wanted to know whether on how can i send e-mails to more than one person and also if i can put one of the names in cc list .

Thanx'

Akhil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 09:46 AM

    Hi:

    1. You can add as many recipients to the mailrec table. Just add the recipients and append your mailrec.

    • Set recipient - email address here!!!

    mailrec-receiver = 'dsm-ltil@essar.com'.

    mailrec-rec_type = 'U'.

    append mailrec.

    mailrec-receiver = 'zzz@zzz.com'.

    mailrec-rec_type = 'U'.

    append mailrec.

    2. You can include the recipients in 'copy ' or 'Blind copy ' too. The fields to be used are - COPY and BLIND_COPY respectively.

    Eg: mailrec-copy = 'X' or

    mailrec-BLIND_COPY = 'X'.

    Sookshma

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 10:56 AM

    Hi,

    u need to pass these details for sending mail to external mail id in RECEIVERS table of the FM

    • Receivers details

    LT_MAIL_SEND-RECEIVER = LV_MAIL_ID. " Person receiving the mail

    LT_MAIL_SEND-REC_TYPE = 'U'. " Internet mail address

    LT_MAIL_SEND-EXPRESS = 'X'.

    APPEND LT_MAIL_SEND.

    Madhavi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 08:57 AM

    try this function module.

    Z_SENDMAIL_ERROR_STATUS.

    regards.

    venkat.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 09:06 AM

    Check this code,it may help u.

    FORM send_mail USING p_y16m_rcp_par STRUCTURE y16m_rcp_par.

    • Have a subject for the mail

    g_s_document_data-obj_name = text-t02.

    g_s_document_data-obj_descr = text-t03.

    • Fill receiver information

    g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.

    g_s_receivers-rec_id = p_y16m_rcp_par-rec_id.

    g_s_receivers-express = 'X'.

    APPEND g_s_receivers TO g_t_receivers.

    • Call function to send mail

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = g_s_document_data

    document_type = 'RAW'

    • PUT_IN_OUTBOX = ' '

    • IMPORTING

    • SENT_TO_ALL =

    • NEW_OBJECT_ID =

    TABLES

    • OBJECT_HEADER =

    object_content = g_t_object_content

    • CONTENTS_HEX =

    • OBJECT_PARA =

    • OBJECT_PARB =

    receivers = g_t_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

    .

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    ENDFORM. " SEND_MAIL

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Thanks your ur response but y16m_rcp_par dost not exist in my SAP environment. Guess this is a user-defined structure. I have already send the code for your reference request to plzz suggest changes according to that code.

      Cheers!

      Akhil

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 10:05 AM

    Hi,

    May be you can try this.

    DATA: OBJCONT LIKE SOLISTI1 OCCURS 5 WITH HEADER LINE.

    DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

    DATA: DOC_CHNG LIKE SODOCCHGI1.

    DATA: ENTRIES LIKE SY-TABIX.

    DATA: NAME(15).

    • Fill the document

    DOC_CHNG-OBJ_NAME = 'URGENT'.

    DOC_CHNG-OBJ_DESCR = 'Read at once !'.

    DOC_CHNG-SENSITIVTY = 'P'.

    OBJCONT = 'Hey guys, time for lunch !!!'.

    APPEND OBJCONT.

    OBJCONT = 'Lets get going !'.

    APPEND OBJCONT.

    DESCRIBE TABLE OBJCONT LINES ENTRIES.

    READ TABLE OBJCONT INDEX ENTRIES.

    DOC_CHNG-DOC_SIZE = ( ENTRIES - 1 ) * 255 + STRLEN( OBJCONT ).

    • Fill the receiver list

    CLEAR RECLIST.

    RECLIST-RECEIVER = SY-UNAME. " replace with <login name>

    RECLIST-REC_TYPE = 'B'.

    RECLIST-EXPRESS = 'X'.

    APPEND RECLIST.

    CLEAR RECLIST.

    RECLIST-RECEIVER = 'ned.neighbour@next.door.com'.

    RECLIST-REC_TYPE = 'U'.

    APPEND RECLIST.

    • Send the document

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

    EXPORTING

    DOCUMENT_TYPE = 'RAW'

    DOCUMENT_DATA = DOC_CHNG

    PUT_IN_OUTBOX = 'X'

    TABLES

    OBJECT_CONTENT = OBJCONT

    RECEIVERS = RECLIST

    EXCEPTIONS

    TOO_MANY_RECEIVERS = 1

    DOCUMENT_NOT_SENT = 2

    OPERATION_NO_AUTHORIZATION = 4

    OTHERS = 99.

    CASE SY-SUBRC.

    WHEN 0.

    LOOP AT RECLIST.

    IF RECLIST-RECEIVER = SPACE.

    NAME = RECLIST-REC_ID.

    ELSE.

    NAME = RECLIST-RECEIVER.

    ENDIF.

    IF RECLIST-RETRN_CODE = 0.

    WRITE: / NAME, ': succesfully sent'.

    ELSE.

    WRITE: / NAME, ': error occured'.

    ENDIF.

    ENDLOOP.

    WHEN 1.

    WRITE: / 'Too many receivers specified !'.

    WHEN 2.

    WRITE: / 'No receiver got the document !'.

    WHEN 4.

    WRITE: / 'Missing send authority !'.

    WHEN OTHERS.

    WRITE: / 'Unexpected error occurred !'.

    ENDCASE.

    *REWARD if this helps.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Thanks for ur response. But this code works fine when the mails are to be fired to User's SAP inbox but the mail is not raching to the user having external e-mail id(not having SAP login) .

      Please help in sorting out this............as I am able to send mail to external id thru FM 'SO_OBJECT_SEND' but not thru 'SO_NEW_DOCUMENT_SEND_API1'.

      But I cant use 'SO_OBJECT_SEND' due to version upgrade problem associated with it .

      Cheers!

      Akhil

  • author's profile photo Former Member
    Former Member
    Posted on Oct 18, 2006 at 11:01 AM

    hi,

    i think its because of ur wrong declaration of the table check u need to declare your MAILREC table as

    like SOMLRECI1 occurs 0 with header line and not as

    data: mailrec like somlrec90 occurs 0 with header line.

    Madhavi

    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.