2008 Sep 05 7:15 AM
Hi,
I have written a program to send emails as shown in SAP example programs, I am not able to send the emails.
I have ran some of the SAP example programs
BCS_EXAMPLE_1
BCS_EXAMPLE_2
BCS_EXAMPLE_3
BCS_EXAMPLE_4
BCS_EXAMPLE_5
BCS_EXAMPLE_6
I still don't see email in SOST. Is there any thing apart from this code we need to do in the settings to send the email then please let me know.
Regards
Sandeep
2008 Sep 05 8:40 AM
Hi Sandeep,
YOu need to setup the SMTP and mail configurations using the Transaction SCOT.
You can ask your BASIS to do the setting for you.
Once done, you can start sending the mails.
You can also send external mails like yahoo etc.
regards,
Pranu
Hi,
I have written a program to send emails as shown in SAP example programs, I am not able to send the emails.
I have ran some of the SAP example programs
BCS_EXAMPLE_1
BCS_EXAMPLE_2
BCS_EXAMPLE_3
BCS_EXAMPLE_4
BCS_EXAMPLE_5
BCS_EXAMPLE_6
I still don't see email in SOST. Is there any thing apart from this code we need to do in the settings to send the email then please let me know.
Regards
Sandeep
2008 Sep 05 7:18 AM
2008 Sep 05 7:22 AM
Hi Sandeep,
You can refer this code:
FORM mail_pdf .
*&--Send PDF Form by E-Mail
TRY.
send_request = cl_bcs=>create_persistent( ).
*get PDF xstring and convert it to BCS format
lp_pdf_size = XSTRLEN( ls_formoutput-pdf ).
pdf_content = cl_document_bcs=>xstring_to_solix(
ip_xstring = ls_formoutput-pdf ).
IF nast-kschl = c_zhpl.
w_subject = text-001.
ELSEIF nast-kschl = c_zhcs.
w_subject = text-002.
ENDIF.
document = cl_document_bcs=>create_document(
i_type = c_pdf
i_hex = pdf_content
i_length = lp_pdf_size
i_subject = w_subject ).
*add document to send request
send_request->set_document( document ).
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
username = sy-uname
TABLES
return = t_return
addsmtp = t_addr.
CLEAR w_addr.
READ TABLE t_addr INTO w_addr INDEX 1.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = w_addr-e_mail ).
*add recipient to send request
send_request->add_recipient( i_recipient = recipient ).
sent_to_all = send_request->send(
i_with_error_screen = c_x ).
IF sent_to_all = c_x.
MESSAGE i022(so).
ENDIF.
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
*Exception Handing
MESSAGE ID bcs_exception->msgid TYPE bcs_exception->msgty
NUMBER bcs_exception->msgno
WITH bcs_exception->msgv1 bcs_exception->msgv2
bcs_exception->msgv3 bcs_exception->msgv4.
EXIT.
ENDTRY.
ENDFORM. " MAIL_PDF
Regards,
Hemant
Edited by: Hemant Goyal on Sep 5, 2008 8:22 AM
Edited by: Hemant Goyal on Sep 5, 2008 8:23 AM
2008 Sep 05 8:12 AM
Sandeep,
Refer to this blog for configuring..
Or you can try this program if there is nothing wrong with your configuration.
report yh_email1.
data: email type somlreci1-receiver value '<email id>'.
data: sender type soextreci1-receiver value 'SAPDEV02'.
data: imessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs 0 with header line,
ireceivers like somlreci1 occurs 0 with header line.
start-of-selection.
clear imessage. refresh imessage.
imessage = 'This is a mail from SAP ECC6'.
append imessage.
imessage = 'Thanks and Regards'.
append imessage.
imessage = 'Indu'.
append imessage.
perform send_email tables imessage
using email
'Mail from Indu'.
***********************************************************************
*
* Form SEND_EMAIL
***********************************************************************
*
form send_email tables pit_message
using email
p_mtitle.
data: xdocdata like sodocchgi1,
xcnt type i.
* Fill the document data.
xdocdata-doc_size = 1.
* Populate the subject/generic message attributes
xdocdata-obj_langu = sy-langu .
xdocdata-obj_name = 'SAPRPT' .
xdocdata-obj_descr = p_mtitle .
clear ipacking_list. refresh ipacking_list.
ipacking_list-transf_bin = space.
ipacking_list-head_start = 1.
ipacking_list-head_num = 0.
ipacking_list-body_start = 1.
describe table imessage lines ipacking_list-body_num.
ipacking_list-doc_type = 'RAW'.
append ipacking_list.
clear ireceivers.
refresh ireceivers.
ireceivers-receiver = email.
ireceivers-rec_type = 'U'.
append ireceivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = xdocdata
put_in_outbox = 'X'
sender_address = sender
commit_work = 'X'
tables
packing_list = ipacking_list
contents_txt = imessage
receivers = ireceivers
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.
*** These two statemnets are used to force the mail to send it to the
*receipeint otherwise we need to go to SOST tcode where we need to press
* F8 to send the mail to the other user. To avoid this we need to use
*these two statemnets. Here the mail is not in queue.
submit rsconn01 using selection-set 'INT' and return.
call function 'SO_DEQUEUE_UPDATE_LOCKS'.
* SUBMIT rsconn01 WITH mode = 'INT'
* WITH output = 'X'
* AND RETURN.
endform.Regards
Indu
2008 Sep 05 8:23 AM
Hi ,
Look at below sample code.
REPORT ZTEST_MAIL .
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.
objtxt = 'The following are the changes made'.
APPEND objtxt.
objtxt = ' '.
APPEND objtxt.
Concatenate ' Row 1 data '
' Old Value '
' New Value '
into objtxt.
append objtxt.
Concatenate '---Row 2 -
'
'----
'
'----
'
'----
'
into objtxt.
append objtxt.
IF NOT objtxt[] IS INITIAL.
Creating the document to be sent
doc_chng-obj_name = 'Name'.
doc_chng-obj_descr = 'Description'.
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'CSV'.
APPEND objpack.
reclist-receiver = 'email address'.
reclist-rec_type = 'U'.
APPEND reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
object_header = objhead
contents_txt = objtxt
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
if sy-subrc = 0.
write: ' email sent succesfully'.
endif.
ENDIF.
Thanks
Mohit Khandelwal
2008 Sep 05 8:40 AM
Hi Sandeep,
YOu need to setup the SMTP and mail configurations using the Transaction SCOT.
You can ask your BASIS to do the setting for you.
Once done, you can start sending the mails.
You can also send external mails like yahoo etc.
regards,
Pranu
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |