2012 Jan 31 9:25 AM
Hi,
Can someone please let me know how can I send a email with formatted body. I am planning to use HTML for formatting.
I am using the method
cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = html
i_length = conlengths
i_subject = subject ).
This is not working. However I am able to attach HTML file to the mail .
Thanks and regards,
Vamsi
2012 Jan 31 9:55 AM
We have used like this and its working
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document( i_type = c_html_format
i_text = it_html_body[]
i_subject = lv_subject_text ).
lo_send_request->set_document( lo_document ).
add recipient with its respective attributes to send request
LOOP AT lt_dist_emails INTO ls_dist_emails.
CLEAR: lo_recipient.
lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_dist_emails-mail_address ).
CALL METHOD lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_express = c_x ).
ENDLOOP .
Add sender email address
CLEAR: lo_recipient.
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_sender_id ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_copy = c_x
i_express = c_x ).
lo_send_request->set_send_immediately( c_x ).
lv_sent_to_all = lo_send_request->send( c_x ).
COMMIT WORK.
CATCH cx_bcs INTO lo_exception.
EXIT.
ENDTRY.
2012 Jan 31 9:55 AM
We have used like this and its working
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document( i_type = c_html_format
i_text = it_html_body[]
i_subject = lv_subject_text ).
lo_send_request->set_document( lo_document ).
add recipient with its respective attributes to send request
LOOP AT lt_dist_emails INTO ls_dist_emails.
CLEAR: lo_recipient.
lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_dist_emails-mail_address ).
CALL METHOD lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_express = c_x ).
ENDLOOP .
Add sender email address
CLEAR: lo_recipient.
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_sender_id ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient
i_copy = c_x
i_express = c_x ).
lo_send_request->set_send_immediately( c_x ).
lv_sent_to_all = lo_send_request->send( c_x ).
COMMIT WORK.
CATCH cx_bcs INTO lo_exception.
EXIT.
ENDTRY.
2012 Jan 31 9:58 AM
Hi John,
I am using the same/similar coding. Still its not working.
Any system configuration required for this?
Thanks and regards,
Vamsi
2012 Jan 31 10:02 AM
Hi Mohana,
Did you check transaction SCOT if you didnt use set_send_immediately?
2012 Jan 31 10:00 AM
Hi mohana,
Check this:
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
** Change this part with your customized document type.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_BODY
i_subject = SUBJECT ).
* add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'XL' "make tihis type HTML
i_attachment_subject = SUBJECT
i_attachment_size = size
i_att_content_hex = binary_content ). "fill binary_content
* add document object to send request
send_request->set_document( document ).
* --------- add recipient (e-mail address) -----------------------
* create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailrec ).
* add recipient object to send request
send_request->add_recipient( recipient ).
* ---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
2012 Jan 31 10:09 AM
Hi,
I am able to trigger the mail.
However, if I am using format as RAW, the text is coming in the mail body.
If I use format as HTM, email body is blank.
Thanks and regards,
Vamsi
2012 Jan 31 10:43 AM
Hi Vamsi,
Use HTML tags while preparing your final table which will be send as an attchment.
select the HTML tags which suits your requirement and prepare the internal table by cancatenating HTML tags and your code.
pass that internal table as an attachment.
<p><font size="2" face="arial">
"write the text you want to display
" Use <br> tab for new line
</font></p>
2012 Jan 31 10:52 AM
Hi,
This is my internal table.
html_wa = '<body>'.APPEND html_wa to html.
*html_wa = '<table>'.APPEND html_wa to html.
html_wa = '<b> Hello </b>'.APPEND html_wa to html.
html_wa = '<br>'.APPEND html_wa to html.
html_wa = '<text>This is test</text>'.APPEND html_wa to html.
*html_wa = '</table>'.APPEND html_wa to html.
html_wa = '</body>'.APPEND html_wa to html.
With regards,
Vamsi
2012 Jan 31 10:59 AM
Hi Vamsi,
If you want to dispaly the text 'HELLO' inside the table then you need to use proper Table tags. You can also define the properties of table.
<table style="font-family: Arial; font-size:"2";>
<tr>
<td> 'HELLO'</td>
</tr>
</table>
But I think Table tag and Body tag not required in this case...Text tag alone will work.
Regards,
Karuna N
2012 Jan 31 2:14 PM
Hi Mohana,
Please use the below FM first to convert raw text to HTML and then append the html data to final FM.
Please check the below piece of code which we have used and its working.
Header record for converting to HTML
ls_header-tdname = zemailtxt.
ls_header-tdspras = 'E'.
ls_header-tdid = 'ST'.
ls_header-tdobject = 'TEXT'.
ls_header-tdstyle = 'system'.
FM to convert SAP script to HTML
CALL FUNCTION 'CONVERT_ITF_TO_HTML'
EXPORTING
i_header = ls_header
TABLES
t_itf_text = lt_lines
t_html_text = lt_html
EXCEPTIONS
syntax_check = 1
replace = 2
illegal_header = 3
OTHERS = 4.
REFRESH gt_content.
Populate email body to an internal table
LOOP AT lt_html INTO ls_html.
lwa_content = ls_html-tdline.
APPEND lwa_content TO gt_content.
CLEAR lwa_content.
ENDLOOP.
Populate the packing details of Mail body
CLEAR : gv_lines.
DESCRIBE TABLE gt_content LINES gv_lines.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 0.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = gv_lines.
lwa_objpack-doc_type = 'HTM'.
APPEND lwa_objpack TO lit_objpack.
-- Some code for header and doc size ..
*-- FM for sending email to NERC Team,
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gs_doc_chng
put_in_outbox = 'X'
sender_address = lv_sender_mail
sender_address_type = lv_add_type
commit_work = gc_x
TABLES
packing_list = lit_objpack
contents_txt = gt_content
receivers = gt_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.
ENDIF.
2013 Sep 13 12:06 PM
Hi Srikanth,
could you please explain me process , html features are not getting to my mail .
here i am attached code and screenshot of output. please help me
2012 Jan 31 2:47 PM
Hi
See the article [Step by Step Process of Preparing E-mail with HTML body and HTML Attachment|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/e009f97e-ee5d-2e10-31ba-9c9509e5925c] by Sri Hari Anand Kumar.
Regards
Eduardo
2012 Feb 01 11:21 AM
Hi,
If I use RAW as type, the text is coming in the mail body.
If I use HTM, its not coming in the body. Do I have to configure anything to send HTM object type?
Thanks and regards,
Vamsi
2012 Feb 01 11:29 AM
Hi friend,
Please go through this white paper.
Link : [Steps for sending email with HTML attachment|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e009f97e-ee5d-2e10-31ba-9c9509e5925c?QuickLink=index&overridelayout=true]
You can just copy and paste the code it will work fine.
You can just change the logic accordingly. Also see the system is configured to sent emails.
I think this will solve your issue. If you face any difficulties in code revert back to me i will help you.
Thanks,
Sri Hari
2012 Feb 18 12:37 PM
please prepare your email body content like below code, then pass it to cl_document_bcs=>create_document
Data: result_content type string.
*refresh text .
clear result_content .
*The body message
concatenate
'<p><font color="#000080">This is the first line in the email body</font></p>'
'<p><font color="#000080">Second line </font></p>'
'<p><font color="#000080">third line and thank you. </font></p>'
into result_content .
conlength = strlen( result_content ) .
conlengths = conlength .
call function 'SCMS_STRING_TO_FTEXT'
exporting
text = result_content
tables
ftext_tab = text.
try.
clear send_request .
send_request = cl_bcs=>create_persistent( ).
clear document .
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = text
i_length = conlengths
i_subject = subject ).
2015 Aug 27 3:22 PM
Hello Mohana,
I just faced a related issue. The problem was that in transaction "SOST" menu "SAP Connect Administration" / Settings / Outbound Messages a disclosure was maintained. This disclosure prevented to show the HTML-text in the email body. Instead my body-text was added to the attachment.