‎2010 Nov 09 6:57 AM
Hello,
I found the following program on the internet. When i run it i get the status as mail sent, but actually the mail is not delivered to the recipients email address. If i check tcode SBWP, a copy of the sent mail sits in outbox even though it is not actually delivered to the receivers. The domain name is set properly in tcode SCOT. Any attempt to send mail directly using tcode SBWP works fine and a copy of the mail goes in outbox. However mails from the program only go in outbox but are not actually sent.Pls help. The program is as under
REPORT ZSENDEXTERNAL.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
Mail Contents
OBJTXT = 'Minimum bid : $250000'.
APPEND OBJTXT.
OBJTXT = 'A representation of the pictures up for auction'.
APPEND OBJTXT.
OBJTXT = 'was included as attachment.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of 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 = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
*OBJBIN = ' \O/ '. APPEND OBJBIN.
*OBJBIN = ' | '. APPEND OBJBIN.
*OBJBIN = ' / \ '. APPEND OBJBIN.
*DESCRIBE TABLE OBJBIN LINES TAB_LINES.
*OBJHEAD = 'PICTURE.BMP'.
*APPEND OBJHEAD.
Creation of the entry for the compressed attachment
*OBJPACK-TRANSF_BIN = 'X'.
*OBJPACK-HEAD_START = 1.
*OBJPACK-HEAD_NUM = 1.
*OBJPACK-BODY_START = 1.
*OBJPACK-BODY_NUM = TAB_LINES.
*OBJPACK-DOC_TYPE = 'BMP'.
*OBJPACK-OBJ_NAME = 'PICTURE'.
*OBJPACK-OBJ_DESCR = 'Representation of object 138'.
*OBJPACK-DOC_SIZE = TAB_LINES * 255.
*APPEND OBJPACK.
Completing the recipient list
RECLIST-RECEIVER = 'email addr'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
*RECLIST-RECEIVER = 'SAPUSERNAME'.
*RECLIST-REC_TYPE = 'P'.
*APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT RECLIST.
WRITE: / RECLIST-RECEIVER(48), ':'.
IF RECLIST-RETRN_CODE = 0.
WRITE 'The document was sent'.
ELSE.
WRITE 'The document could not be sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
‎2010 Nov 09 1:37 PM
Hi,
DATA: l_send_request TYPE REF TO cl_bcs, " Send request
l_body TYPE bcsy_text, " Mail body
l_attach TYPE bcsy_text, " Attachment
wa_text TYPE soli, " Work area for attach
l_document TYPE REF TO cl_document_bcs, " Mail body
l_sender TYPE REF TO if_sender_bcs, " Sender address
l_recipient TYPE REF TO if_recipient_bcs, " Recipient
l_size TYPE sood-objlen, " Size of Attachment
c_tab type abap_char1 value
cl_abap_char_utilities=>horizontal_tab,
l_lines TYPE i, " Lines count
l_email type ad_smtpadr, " Email ID
l_extension type soodk-objtp value 'OTF'. " TXT format
wa_text = 'Contents'.
APPEND wa_text TO l_body.
CLEAR wa_text .
l_send_request = cl_bcs=>create_persistent( ).
Craete document for mail body
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_body
i_subject = 'BI PC Log' ).
Add the document to send request
CALL METHOD l_send_request->set_document( l_document ).
Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
Recipient address
l_email =<ur_emailid>.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
Add recipient address to send request
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'X'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).
Send mail
CALL METHOD l_send_request->send( ).
COMMIT WORK.
Regards,
KC
‎2010 Nov 09 8:18 AM
Hello,
"copy of the sent mail sits in outbox even though it is not actually delivered to the receivers"
The reason for mails getting saved in outbox is because of the code in the program while sending mail
using FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' i.e. the parameter PUT_IN_OUTBOX = 'X' .
For the mails not getting saved, you can check the status of the email in t-code SOST.
Hope this helps you.
Regards,
M M Jaffer
‎2010 Nov 09 8:25 AM
Thanks..but wht changes do i have to make in the program so that emails are actually sent to the recipients
‎2010 Nov 09 9:24 AM
Hi,
Forget FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' .
Look at BCS* reports.
You will never again have any trouble with any mail problem - Search SDN!
Regards,
Clemens
‎2010 Nov 09 9:29 AM
Hi
I guess there would be a batch job scheduled to deliver the messages to the perticular receipant.
Go to transaction SCOT.. Menu view -- Jobs...
Regards
Anuja
‎2010 Nov 09 9:36 AM
Hello..I have done that in SCOT transaction. Apparently it looks like something needs to be added in the program. Can anyone pls post an ABAP program in which I should be able to compose the body of the mail, the subject, recipeints etc and send it to the intended recipients
‎2010 Nov 09 9:51 AM
I second Clements approach to use the BCS classes. If you want your current program to work do as below,
Change the below line from
PUT_IN_OUTBOX = 'X'
TO
PUT_IN_OUTBOX = space
Regards
Ranganath
‎2010 Nov 09 10:30 AM
Hello..I tried setting PUT_IN_OUTBOX = space.
No copy of the mail is put in outbox, but the problem still persists...the recipient still does not receive the email.
‎2010 Nov 09 12:54 PM
‎2010 Nov 09 1:37 PM
Hi,
DATA: l_send_request TYPE REF TO cl_bcs, " Send request
l_body TYPE bcsy_text, " Mail body
l_attach TYPE bcsy_text, " Attachment
wa_text TYPE soli, " Work area for attach
l_document TYPE REF TO cl_document_bcs, " Mail body
l_sender TYPE REF TO if_sender_bcs, " Sender address
l_recipient TYPE REF TO if_recipient_bcs, " Recipient
l_size TYPE sood-objlen, " Size of Attachment
c_tab type abap_char1 value
cl_abap_char_utilities=>horizontal_tab,
l_lines TYPE i, " Lines count
l_email type ad_smtpadr, " Email ID
l_extension type soodk-objtp value 'OTF'. " TXT format
wa_text = 'Contents'.
APPEND wa_text TO l_body.
CLEAR wa_text .
l_send_request = cl_bcs=>create_persistent( ).
Craete document for mail body
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_body
i_subject = 'BI PC Log' ).
Add the document to send request
CALL METHOD l_send_request->set_document( l_document ).
Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
Recipient address
l_email =<ur_emailid>.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
Add recipient address to send request
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'X'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).
Send mail
CALL METHOD l_send_request->send( ).
COMMIT WORK.
Regards,
KC
‎2010 Nov 10 5:36 AM