‎2007 Nov 14 7:27 AM
Hi,
I am using below code but not email is being send by this?
Please Suggest the email id not being send and sy-subrc is retruned as 8?
please check on the below code it can be tested also as it is synt correct
Tables : zcustemail.
Declarations.
*PARAMETERS: p_email(50) LOWER CASE.
*
DATA: document_data LIKE sodocchgi1.
DATA: t_content LIKE STANDARD TABLE OF solisti1.
DATA: s_content LIKE solisti1.
DATA: t_receivers LIKE STANDARD TABLE OF somlreci1.
DATA: s_receivers LIKE somlreci1. "occurs 0 with header line.
DATA : begin of it_email,
email_id like zcustemail-email_id,
end of it_email.
DAta: wa_itreceivers like it_email.
data : it_receivers like it_email occurs 0 with header line.
*START-OF-SELECTION.
select email_id from zcustemail into table it_receivers.
loop at it_receivers into wa_itreceivers.
Receivers. " add your receivers here..
s_receivers-receiver = wa_itreceivers-email_id.
s_receivers-rec_type = 'U'.
s_receivers-express = 'X'.
APPEND s_receivers TO t_receivers.
endloop.
*LOOP AT et_mailid.
*CLEAR i_receivers.
*i_receivers-receiver = et_mailid-email_id.
*i_receivers-rec_type = 'U'.
*i_receivers-com_type = 'INT'.
*i_receivers-notif_del = 'X'.
*i_receivers-notif_ndel = 'X'.
*APPEND i_receivers.
*ENDLOOP.
Subject
document_data-obj_descr = 'New mail from Sap'.
Body
s_content = 'Hi,'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Test email from sap, please don''t reply to this email'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Thanks,'.
APPEND s_content TO t_content.
s_content = 'Naren.'.
APPEND s_content TO t_content.
Send the email.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
TABLES
object_content = t_content
receivers = 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 e208(00) WITH 'Error in sending email :-(('.
ELSE.
MESSAGE s208(00) WITH 'Email sent )'.
ENDIF.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
regards
Nishant
‎2007 Nov 14 2:36 PM
Hi Nishant,
I tried the code written below and it is working absolutely fine for me. Why don't you try the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'. it is working correctly woth no error
DATA: g_sent_all(1) TYPE c,
g_doc_data LIKE sodocchgi1,
g_error TYPE sy-subrc.
DATA: t_content LIKE solisti1 OCCURS 0 WITH HEADER LINE,
s_content LIKE solisti1,
i_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF it_receivers OCCURS 0,
email_id TYPE so_recname,
END OF it_receivers.
CONSTANTS: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*START-OF-SELECTION.
SELECT email_id FROM zcustemail INTO TABLE it_receivers.
Add the recipients email address
LOOP AT it_receivers.
CLEAR i_receivers.
i_receivers-receiver = it_receivers-email_id.
i_receivers-rec_type = 'U'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
ENDLOOP.
Fill the document data.
g_doc_data-doc_size = 1.
Populate the subject/generic message attributes
g_doc_data-obj_langu = sy-langu.
g_doc_data-obj_name = 'SAPRPT'.
g_doc_data-obj_descr = 'New mail from SAP' .
g_doc_data-sensitivty = 'F'.
Describe the body of the message
Information about structure of data tables
CLEAR i_packing_list.
REFRESH i_packing_list.
i_packing_list-transf_bin = space.
i_packing_list-head_start = 1.
i_packing_list-head_num = 0.
i_packing_list-body_start = 1.
DESCRIBE TABLE t_content LINES i_packing_list-body_num.
i_packing_list-doc_type = 'RAW'.
APPEND i_packing_list.
Body
s_content = 'Hi,'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Test email from sap, please don''t reply to this email'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Thanks,'.
APPEND s_content TO t_content.
s_content = 'Naren.'.
APPEND s_content TO t_content.
Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = g_doc_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_all
TABLES
packing_list = i_packing_list
contents_txt = t_content
receivers = i_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
g_error = sy-subrc.
Get i_receivers return code
LOOP AT i_receivers.
ENDLOOP.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
IF g_error EQ 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
Hope it helps,
Regards,
Amit
‎2007 Nov 14 12:23 PM
Hi Nishant,
Pass doc type and commit_work values also.
below code for your reference.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = lwa_document_data
document_type = c_doc_type
commit_work = 'X'
TABLES
object_content = lit_contents
receivers = lit_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.<b>Reward Points if it helps</b>
Satish
‎2007 Nov 15 2:34 AM
hi satish
can u pls eloborate on c_doc_type
what this variable or constant holds?
regards
Arora
‎2007 Nov 15 9:33 AM
Hi,
I used c_doc_type as 'HTM', you can use as per your requirement.
<b>Reward Points for helpful answers</b>
Satish
‎2007 Nov 14 2:36 PM
Hi Nishant,
I tried the code written below and it is working absolutely fine for me. Why don't you try the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'. it is working correctly woth no error
DATA: g_sent_all(1) TYPE c,
g_doc_data LIKE sodocchgi1,
g_error TYPE sy-subrc.
DATA: t_content LIKE solisti1 OCCURS 0 WITH HEADER LINE,
s_content LIKE solisti1,
i_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF it_receivers OCCURS 0,
email_id TYPE so_recname,
END OF it_receivers.
CONSTANTS: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*START-OF-SELECTION.
SELECT email_id FROM zcustemail INTO TABLE it_receivers.
Add the recipients email address
LOOP AT it_receivers.
CLEAR i_receivers.
i_receivers-receiver = it_receivers-email_id.
i_receivers-rec_type = 'U'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
i_receivers-notif_ndel = 'X'.
APPEND i_receivers.
ENDLOOP.
Fill the document data.
g_doc_data-doc_size = 1.
Populate the subject/generic message attributes
g_doc_data-obj_langu = sy-langu.
g_doc_data-obj_name = 'SAPRPT'.
g_doc_data-obj_descr = 'New mail from SAP' .
g_doc_data-sensitivty = 'F'.
Describe the body of the message
Information about structure of data tables
CLEAR i_packing_list.
REFRESH i_packing_list.
i_packing_list-transf_bin = space.
i_packing_list-head_start = 1.
i_packing_list-head_num = 0.
i_packing_list-body_start = 1.
DESCRIBE TABLE t_content LINES i_packing_list-body_num.
i_packing_list-doc_type = 'RAW'.
APPEND i_packing_list.
Body
s_content = 'Hi,'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Test email from sap, please don''t reply to this email'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Thanks,'.
APPEND s_content TO t_content.
s_content = 'Naren.'.
APPEND s_content TO t_content.
Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = g_doc_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_all
TABLES
packing_list = i_packing_list
contents_txt = t_content
receivers = i_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
g_error = sy-subrc.
Get i_receivers return code
LOOP AT i_receivers.
ENDLOOP.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
IF g_error EQ 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
Hope it helps,
Regards,
Amit
‎2007 Nov 15 2:24 AM
hi amit
the below statement in ur code is giving error ?
CONSTANTS: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
with msg class cl_abap_char_utilities unknown
and can u pls eloborate more on ur code
specially last part it not clear why it is being done so and loo at i_receivers done?
Please eloborate and sugesst me on the above error
Store function module return code
g_error = sy-subrc.
Get i_receivers return code
LOOP AT i_receivers.
ENDLOOP.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
IF g_error EQ 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
regards
Arora
‎2007 Nov 15 2:30 AM
hi Amit
also i tried to comment that class part
in the function module call
the return code is being sy-subrc is = 2?
and no email is being send as exception 2 is being raised?
Please suggest how its working fine for u?
Please eloborate and suggest
regards
ARora
‎2007 Nov 15 6:58 AM
hi amit
can u u pls reply on my query u say it is working fine at ur end ?
i got this error related to the class as i have explained in above mails
Pls suggest
Hi alll
can any one reply on this
regards
Arora
‎2007 Nov 15 8:03 AM
Hi Nishant,
As I told you earlier, it is working fine in my system. You can remove that Class usage from program as it is not required.I think you should check your Email setting or contact a Basis guy.
Regards,
Amit
‎2007 Nov 16 3:53 AM
hi amit
can u pls eloborate more
as what needs to be checked in email settings its normal outlook inbox where i am trying to send email
but the fm is not working properly as SY-SUBRC <> 0 IN MY CASE ITS RETURNING 2 AS NO DOCUMENT
i dont want to send any document jsut a email with msg
can it be done with this FM
and if yes please let me know how to do it the code ?
Please suggest
regards
Arora