Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HTML formatted mail body

Former Member
0 Likes
8,893

Hi Guys,

I am having some issue with sending html formatted mail in text body. I am using cl_bcs and cl_document_bcs.

When I create the document and give the document type as 'TXT', then the content is present in the mail body. But when I give the type as 'HTM', then the mail comes as an attachment. Can anybody please give me the reason for it?

Code used:-

document = cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = html

  • i_header = li_header

  • i_length = conlengths

i_subject = k_subject ).

send_request->set_document( document ).

send_request->set_send_immediately( 'X' ).

recipient = cl_cam_address_bcs=>create_internet_address( k_rec ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

CALL METHOD send_request->set_status_attributes

EXPORTING

i_requested_status = 'N'

i_status_mail = 'N'.

CALL METHOD send_request->set_send_immediately( 'X' ).

sent_to_all = send_request->send( i_with_error_screen = 'X' ).

1 ACCEPTED SOLUTION
Read only

former_member189059
Active Contributor
0 Likes
5,855

Hello,

Although it doesn't use the class you are using, there is a blog which shows how to send e-mail formatted in HTML.

http://help-abap.blogspot.com/2008/09/sapconnect-email-with-formatting.html

Hi Guys,

I am having some issue with sending html formatted mail in text body. I am using cl_bcs and cl_document_bcs.

When I create the document and give the document type as 'TXT', then the content is present in the mail body. But when I give the type as 'HTM', then the mail comes as an attachment. Can anybody please give me the reason for it?

Code used:-

document = cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = html

  • i_header = li_header

  • i_length = conlengths

i_subject = k_subject ).

send_request->set_document( document ).

send_request->set_send_immediately( 'X' ).

recipient = cl_cam_address_bcs=>create_internet_address( k_rec ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

CALL METHOD send_request->set_status_attributes

EXPORTING

i_requested_status = 'N'

i_status_mail = 'N'.

CALL METHOD send_request->set_send_immediately( 'X' ).

sent_to_all = send_request->send( i_with_error_screen = 'X' ).

7 REPLIES 7
Read only

former_member189059
Active Contributor
0 Likes
5,856

Hello,

Although it doesn't use the class you are using, there is a blog which shows how to send e-mail formatted in HTML.

http://help-abap.blogspot.com/2008/09/sapconnect-email-with-formatting.html

Read only

Former Member
0 Likes
5,855

Thanks Kris,

But, it is still not working. I think there is some issue with the setting in SAP server. I have just found out that the same code is working well in the other server, that is, the content is in the mail body and not as an attachment. But, it is not working in the server I am using. When I send format content as 'htm' , then it sends it as an attachment

Read only

0 Likes
5,855

Your email code looks fine; hopefully your HTML code is fine as well. Check the SAPConnect settings on both servers for FORCE_FIRSTBODY_IS_TEXT. ( SCOT -> Settings -> General Parameters )

Read only

0 Likes
5,855

Hi Brad,

Thiis parameter is not present in any of the two servers I am testing. Do you think I should add this parameter?

Read only

0 Likes
5,855

Well, if neither server has the setting and one server works, then I doubt it's the issue. The FORCE_FIRSTBODY_IS_TEXT setting was primarily used for PDF content to be interpreted correctly in earlier versions with some mail clients, but I also saw one note that covered HTML emails being converted to attachments (1397458). The setting won't hurt; I have it set in our SAPConnect config and most of our emails are HTML-based.

If this doesn't work, use the internal trace function to determine how the email is being handled: SCOT -> Utilities -> Trace Settings. Also, if your html is complicated, start with some basic html and simple text as well to determine if there's an issue with that part of the code.

Read only

Former Member
0 Likes
5,855

Hi Jas,

HTML internal table needs to be built and passed into the method cl_document_bcs=>create_document. Please make sure the HTML for the email content is collected in an internal table.

Thanks and Best Regards,

Dinesh.

cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = int_html

i_length = conlengths

i_subject = wl_subject ).

Internal Table

-


DATA: int_html TYPE TABLE OF w3html,

wf_html LIKE LINE OF int_html.

Built the HTML string and append to the internal table and once you have the complete HTML, create the document.

Read only

Former Member
0 Likes
5,855

Hi Jas,

HTML internal table needs to be built and passed into the method cl_document_bcs=>create_document. Please make sure the HTML for the email content is collected in an internal table.

Thanks and Best Regards,

Dinesh.

cl_document_bcs=>create_document(

i_type = 'HTM'

i_text = int_html

i_length = conlengths

i_subject = wl_subject ).

Internal Table

-


DATA: int_html TYPE TABLE OF w3html,

wf_html LIKE LINE OF int_html.

Built the HTML string and append to the internal table and once you have the complete HTML, create the document.