
Following declaration will be useful.
DATA: p_form TYPE crmt_pml_id,
lr_ref TYPE REF TO cl_crm_pml_mail_form_exec,
lv_subject TYPE xstring,
lt_personalized_mail TYPE crmt_pml_txtsubj_exec_tab,
lt_picture_key TYPE crmt_pml_exec_pic_key_tab,
lt_attachment_key TYPE skwf_ios,
lt_messages TYPE bapiret2_t,
lv_pers_mail_type TYPE crmt_pml_type,
lv_date TYPE bcos_tstmp,
lt_bo TYPE sibflporbt,
ls_bo TYPE sibflporb,
lt_return TYPE bapiret2_t,
ls_activity TYPE bapibus20001_object_id,
lv_activity_guid TYPE guid_32,
lt_activity TYPE cmst_bapibus20001_object_id_t,
lv_guid TYPE crmt_object_guid,
l_error TYPE c,
lr_document TYPE REF TO cl_document_bcs,
ls_adsmptp TYPE bapiadsmtp,
lt_adsmptp TYPE TABLE OF bapiadsmtp,
lr_send_request TYPE REF TO cl_bcs,
ls_variable TYPE crmt_pml_name_value,
lt_attr_variable TYPE crmt_pml_name_value_tab,
lt_variable TYPE crmt_pml_name_value_tab.
Step1. First of all get the reference of Mail form that you have created.
p_form = 'MAILFORM001'. "" Mail form ID
CREATE OBJECT lr_ref
EXPORTING
iv_mail_id = p_form
EXCEPTIONS
mail_not_found = 1
OTHERS = 2.
Step 2. Fetch placeholders that you have created in mail form.
CALL METHOD lr_ref->get_variables
RECEIVING
rt_variable = lt_variable.
lt_variable will contain all the placeholders that you have created in your mail form.
Step3. Pass values to the placeholders in mail form
LOOP AT lt_variable INTO ls_variable.
CASE ls_variable-name.
WHEN 'BAPIBUS1006_CENTRAL_PERSON-FULLNAME'.
ls_variable-value = 'ABC'.
WHEN 'BAPIBUS1006_HEAD-BPARTNER'.
ls_variable-value = '400024'.
ENDCASE.
INSERT ls_variable INTO TABLE lt_attr_variable.
ENDLOOP.
In my case i have just used two placeholders.
Step4. Create your mail template using function module 'CRM_IM_CREATE_PERS_MAIL'. Pass your variables table, language of mail and your mail form object reference. The received parameters will be used in sending mail in step 6.
CALL FUNCTION 'CRM_IM_CREATE_PERS_MAIL'
EXPORTING
it_attribute_values = lt_attr_variable
iv_langu = 'E'
ir_exec_service = lr_ref
IMPORTING
ev_subject = lv_subject
et_personalized_mail = lt_personalized_mail
et_picture_key = lt_picture_key
et_attachment_key = lt_attachment_key
et_messages = lt_messages
ev_pers_mail_type = lv_pers_mail_type
EXCEPTIONS
mail_empty = 1
OTHERS = 2.
Step5. Create an activity to which the mail will get attached. The activity will then be visible in the Interaction history of the order for which you were sending mail. Use method 'create_activity' of utility class 'cl_crm_email_utility'.
GET TIME STAMP FIELD lv_date.
lv_guid = 'XXXXXXXXXXXXX'. ""Enter guid of order for which you want to create follow up activity
ls_bo-instid = lv_guid.
ls_bo-typeid = 'BUS2000120'. "" Business object for complaints
ls_bo-catid = 'BO'.
INSERT ls_bo INTO TABLE lt_bo.
CALL METHOD cl_crm_email_utility=>create_activity
EXPORTING
iv_process_type = '0005'
iv_description = 'Created using mail form'
iv_start_date = lv_date
it_link_bo = lt_bo
iv_direction = '1'
iv_status_process = 'FINI'
IMPORTING
et_return = lt_return
et_activities = lt_activity.
READ TABLE lt_activity INTO ls_activity INDEX 1.
lv_activity_guid = ls_activity-guid.
Step6. Activity for mail and mail template has been created. Now we have to attach both and Send mail using function module 'CRM_IM_SEND_PERSONALIZED_MAIL'. Enter the receiver's email address, sender email address, reply-to email address,
mail form id and other mail form template variables.
ls_adsmptp-e_mail = 'test@abc.com'. "" Receiver mail address
ls_adsmptp-std_no = 'X'.
INSERT ls_adsmptp INTO TABLE lt_adsmptp.
CALL FUNCTION 'CRM_IM_SEND_PERSONALIZED_MAIL'
EXPORTING
iv_device = 'MAIL'
iv_sender = 'abc@abc.com' "" sender email address
iv_reply = 'reply@abc.com'
iv_mailform = 'MAILFORM001'
iv_activity_guid = lv_activity_guid
iv_pers_mail_type = lv_pers_mail_type
it_picture_keys = lt_picture_key
iv_subject = lv_subject
it_personalized_mail = lt_personalized_mail
it_attachment_key = lt_attachment_key
IMPORTING
er_document = lr_document
er_send_request = lr_send_request
TABLES
it_smtp = lt_adsmptp
CHANGING
cv_error = l_error.
Step 7. 'COMMIT WORK' is important as the mail will not be sent untill this is executed.
COMMIT WORK.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.