‎2009 Jul 08 10:49 AM
Is there a more recent functionality for sending email? One with a simpler interface? If yes, please post example code. Thanks.
‎2009 Jul 08 10:54 AM
Take a look at these example programs ,
BCS_EXAMPLE_1
BCS_EXAMPLE_2
BCS_EXAMPLE_3
BCS_EXAMPLE_4
BCS_EXAMPLE_5
BCS_EXAMPLE_6.
‎2009 Jul 08 10:54 AM
Take a look at these example programs ,
BCS_EXAMPLE_1
BCS_EXAMPLE_2
BCS_EXAMPLE_3
BCS_EXAMPLE_4
BCS_EXAMPLE_5
BCS_EXAMPLE_6.
‎2009 Jul 08 10:58 AM
Search SCN.you can find solutions to your requirement .
regards
Aakash Banga
‎2009 Jul 08 11:09 AM
check with the below example for sending mail with the same FM if ur not able to achieve with this otherwise you have to check in SDN
elseif ls_control_param-preview is initial and
ls_control_param-getotf is not initial.
ls_control_param-GETOTF = 'X'.
ls_control_param-NO_DIALOG = 'X'.
CALL FUNCTION v_form_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
is_ekko = l_doc-xekko
user_settings = ' '"iv_user_settings "Disable User Printer
is_pekko = l_doc-xpekko
is_nast = l_nast
iv_from_mem = l_from_memory
iv_druvo = iv_druvo
iv_xfz = iv_xfz
IMPORTING
JOB_OUTPUT_INFO = w_return
EV_ADDNR_VENDOR = IV_ADDNR_VENDOR
TABLES
it_ekpo = l_doc-xekpo[]
it_ekpa = l_doc-xekpa[]
it_pekpo = l_doc-xpekpo[]
it_eket = l_doc-xeket[]
it_tkomv = l_doc-xtkomv[]
it_ekkn = l_doc-xekkn[]
it_ekek = l_doc-xekek[]
it_komk = l_xkomk[]
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
ent_retco = sy-subrc.
PERFORM protocol_update_i.
get SmartForm protocoll and store it in the NAST protocoll
PERFORM add_smfrm_prot.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'.
IF SY-SUBRC <> 0.
ELSE.
IF OUT-PREVIEW = 'X'.
i_otf[] = w_return-otfdata[].
call function 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
*Fehlerhandling
if sy-subrc = 0.
endif.
loop at i_tline.
translate i_tline using '~'.
concatenate wa_buffer i_tline into wa_buffer.
endloop.
translate wa_buffer using '~'.
do.
i_record = wa_buffer.
append i_record.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
data iv_mailid type AD_SMTPADR.
select single SMTP_ADDR from ADR6 into iv_mailid where ADDRNUMBER =
IV_ADDNR_VENDOR.
*Attachment
refresh:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear wa_objhead.
i_objbin[] = i_record[].
*Create Message Body
*Title and Description
*************i_objtxt = 'test with pdf-Attachment!'.
*************append i_objtxt.
describe table i_objtxt lines v_lines_txt.
read table i_objtxt index v_lines_txt.
wa_doc_chng-obj_name = 'smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'smartform'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
*Main Text
*wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )
*.
clear i_objpack-transf_bin.
*i_objpack-head_start = 1.
*i_objpack-head_num = 0.
*i_objpack-body_start = 1.
*i_objpack-body_num = v_lines_txt.
*i_objpack-doc_type = 'RAW'.
*append i_objpack.
*Attachment
*(pdf-Attachment)
i_objpack-transf_bin = 'X'.
*i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
*Länge des Attachment ermitteln
describe table i_objbin lines v_lines_bin.
read table i_objbin index v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'smart'.
i_objpack-obj_descr = 'test'.
append i_objpack.
clear i_reclist.
i_reclist-receiver = iv_mailid.
i_reclist-rec_type = 'U'.
append i_reclist.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
COMMIT_WORK = 'X'
TABLES
packing_list = i_objpack
*object_header = wa_objhead
CONTENTS_BIN = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
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 'Mail was not sent' type 'E'.
else.
MESSAGE 'Mail was sent Succesfully' type 'S'.
ENDIF.
‎2009 Jul 08 11:42 AM
‎2009 Aug 02 6:50 AM
Seriously Aakash, don't waste your time or mine with meaningless responses. If I could find something useful, I wouldn't have posted this question.
‎2009 Aug 02 10:51 AM
Dear Adrian.
See if you can make head or tail to this code:
TYPES: BEGIN OF ty_attachments.
INCLUDE STRUCTURE sopcklsti1.
TYPES: END OF ty_attachments.
TYPES: ty_t_attachments TYPE TABLE OF ty_attachments INITIAL SIZE 10.
*Table with data on each attachment.
DATA: gt_attachments TYPE ty_t_attachments.
*Structure - mainly for the Email subject.
DATA: gs_doc_data TYPE sodocchgi1.
*Email object number.
DATA: gs_object_id TYPE sofolenti1-object_id.
*Table of recipient list.
DATA: gt_recivers TYPE TABLE OF somlreci1 INITIAL SIZE 0.
*Table of the Email content (body).
DATA: gt_content TYPE soli_tab.
*Table of email details.
DATA: gt_objpack TYPE TABLE OF sopcklsti1 INITIAL SIZE 2.
*
DATA: gv_sender_addr TYPE soextreci1-receiver,
gv_sender_addr_type TYPE soextreci1-adr_typ.
*Table that contain the attachment data.
*************
* NOTE: It has to be converted using FM 'SO_RAW_TO_RTF' before sending.
*************
TYPES: ty_t_text_tab TYPE TABLE OF solisti1 INITIAL SIZE 0.
DATA: gt_text_tab TYPE ty_t_text_tab.
FORM send_email_with_attachment_new
USING pv_file_type TYPE sopcklsti1-doc_type
pv_file_name TYPE sopcklsti1-obj_name
pv_file_desc TYPE sopcklsti1-obj_descr
pv_ok_msg TYPE abap_bool
pv_err_msg TYPE abap_bool
CHANGING pv_error_no TYPE bcs_cxerr.
DATA: lc_send_request TYPE REF TO cl_bcs,
lc_document TYPE REF TO cl_document_bcs,
lf_bcs_exception TYPE REF TO cx_bcs.
DATA: lv_sent_to_all TYPE os_boolean,
lv_att_subject TYPE sood-objdes.
* If no recievers were set - don't process.
IF gt_recivers[] IS INITIAL.
IF pv_err_msg = 'X'.
MESSAGE i032(y1) WITH 'Mail not sent - no receivers set'(a57).
ELSE.
pv_error_no = 1.
ENDIF.
RETURN.
ENDIF.
TRY.
* Create the send request.
lc_send_request = cl_bcs=>create_persistent( ).
* Add recipients in a loop.
PERFORM add_recipients
USING lc_send_request
pv_err_msg
pv_error_no.
CHECK pv_error_no IS INITIAL.
* Set email body.
PERFORM create_email_body
USING lc_document
pv_err_msg
pv_error_no.
CHECK pv_error_no IS INITIAL.
* add list attachment to document
lv_att_subject = pv_file_desc.
lc_document->add_attachment( i_attachment_type = pv_file_type
i_attachment_subject = lv_att_subject
i_att_content_text = gt_text_tab ).
* Add document to send request.
lc_send_request->set_document( lc_document ).
* Send the mail.
lv_sent_to_all = lc_send_request->send( i_with_error_screen = 'X' ).
* If all OK and message flag is on - issue message.
IF lv_sent_to_all = 'X'.
IF pv_ok_msg = 'X'.
MESSAGE i032(y1) WITH 'Email with attachment sent OK'(a59).
ELSE.
pv_error_no = 0.
ENDIF.
ENDIF.
CATCH cx_bcs INTO lf_bcs_exception.
IF pv_err_msg = 'X'.
MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception->error_type
'encountered when sending email.'(a56).
ELSE.
pv_error_no = lf_bcs_exception->error_type.
ENDIF.
ENDTRY.
* Mails with BCS requires COMMIT.
COMMIT WORK.
ENDFORM. "send_email_with_attachment_new
FORM add_recipients
USING pc_send_request TYPE REF TO cl_bcs
pv_err_msg TYPE abp_fform
pv_error_no TYPE bcs_cxerr.
DATA: lf_recipient TYPE REF TO if_recipient_bcs,
lf_bcs_exception TYPE REF TO cx_bcs.
DATA: ls_recivers TYPE somlreci1.
DATA: adr6-smtp_addr TYPE adr6-smtp_addr.
* Initiate error flag.
CLEAR: pv_error_no.
* If no recievers were set - don't process.
IF gt_recivers[] IS INITIAL.
IF pv_err_msg = 'X'.
MESSAGE i000(y1) WITH 'Mail not sent - no receivers set'(a57).
ELSE.
pv_error_no = 1.
ENDIF.
RETURN.
ENDIF.
LOOP AT gt_recivers INTO ls_recivers.
adr6-smtp_addr = ls_recivers-receiver.
TRY.
lf_recipient = cl_cam_address_bcs=>create_internet_address( adr6-smtp_addr ).
pc_send_request->add_recipient( i_recipient = lf_recipient ).
CATCH cx_bcs INTO lf_bcs_exception.
IF pv_err_msg = 'X'.
MESSAGE i000(y1) WITH 'Error number' lf_bcs_exception->error_type
'encountered when adding recipient.'.
ELSE.
pv_error_no = 2.
ENDIF.
ENDTRY.
ENDLOOP.
ENDFORM. "Add_Recipients
FORM create_email_body
USING pc_document TYPE REF TO cl_document_bcs
pv_err_msg TYPE abp_fform
pv_error_no TYPE bcs_cxerr.
DATA: ls_content TYPE soli,
lf_bcs_exception TYPE REF TO cx_bcs.
DATA: lv_mail_subject TYPE so_obj_des,
lv_i_type TYPE so_obj_tp.
* Initiate error flag.
CLEAR: pv_error_no.
* Convert Mail subject to BCS type.
lv_mail_subject = gs_doc_data-obj_descr.
TRY.
* Create without Email body.
IF gt_content[] IS INITIAL.
pc_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_subject = lv_mail_subject ).
EXIT.
ENDIF.
* Check if GT_CONTENT have HTML code and set type accordingly.
READ TABLE gt_content INTO ls_content INDEX 1.
IF ls_content-line CS '<HTML>'.
lv_i_type = 'HTM'.
ELSE.
lv_i_type = 'RAW'.
ENDIF.
* Create email's body.
pc_document = cl_document_bcs=>create_document(
i_type = lv_i_type
i_text = gt_content
i_subject = lv_mail_subject ).
CATCH cx_bcs INTO lf_bcs_exception.
IF pv_err_msg = 'X'.
MESSAGE i000(y1) WITH 'Error'(a55) lf_bcs_exception->error_type
'encountered when creating email body.'(a60).
ELSE.
pv_error_no = 3.
ENDIF.
ENDTRY.
ENDFORM. "Set_Email_BodySee if this can help.
Ayal Telem.