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

getting message as attachment!!

Former Member
0 Likes
972

Hi all,,

I have an ABAP program where i could send mails to the recipients.

But the recipients are able to receive the content of the mails only in attached pdf format.

But could not get as a body content in the email.

I had passed packing_list-Document type = 'RAW' in in so_document_send_API1

What should i need to do in the settings..

will be awarded..

thanks in adv!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
850

Hi,

Refer to the below code. It works fine to send emails with text body as well as attachments.

PS: If this solves your question pl mark it answered.

Regards.

_______________________

REPORT zmfv_rough_pad.

DATA :

li_attachment TYPE TABLE OF soli, " hold attachment contents

li_pdf TYPE TABLE OF tline, " hold data from spool in PDF format

li_objpack TYPE TABLE OF sopcklsti1, " hold email body, attachment details

li_objtxt TYPE TABLE OF solisti1, " hold message contents

li_reclist TYPE TABLE OF somlreci1. " hold email reciever details

DATA :

lwa_attachment LIKE LINE OF li_attachment,

lwa_pdf LIKE LINE OF li_pdf,

lwa_objpack LIKE LINE OF li_objpack,

lwa_objtxt LIKE LINE OF li_objtxt,

lwa_reclist LIKE LINE OF li_reclist,

lwa_document_data TYPE sodocchgi1. " hold document details like title, size etc.

*

DATA :

lv_sent_to_all TYPE c, " flag to check if mail is sent to all

l_att_lines TYPE i, " hold number of lines in attachment table

lv_spool_desc(68) TYPE c. " hold description of spool

*

CONSTANTS : lc_email_txt TYPE solisti1-line VALUE 'Find attached Payment Advice sent by this email.',

lc_sensitivity TYPE sodocchgi1-sensitivty VALUE 'O',

lc_raw TYPE sopcklsti1-doc_type VALUE 'RAW',

lc_pdf TYPE sopcklsti1-doc_type VALUE 'PDF',

lc_transf_bin TYPE sopcklsti1-transf_bin VALUE 'X',

lc_email TYPE sopcklsti1-obj_name VALUE 'Email',

lc_ext_id TYPE somlreci1-rec_type VALUE 'U',

lc_outbox TYPE sonv-flag VALUE 'X',

lc_obj_name TYPE sodocchgi1-obj_name VALUE 'Email Test',

lc_1 TYPE n VALUE '1',

lc_0 TYPE n VALUE '0'.

*

CLEAR: lwa_attachment,

lwa_pdf,

lwa_reclist,

lwa_objtxt,

lwa_objpack,

lwa_document_data.

*

REFRESH : li_attachment,

li_pdf,

li_reclist,

li_objtxt,

li_objpack.

  • Build attachment table

lwa_attachment-line = 'YOUR TEXT FROM INTERNAL TABLE LINES'.

APPEND lwa_attachment TO li_attachment.

  • Body of email

CLEAR lwa_objtxt.

MOVE lc_email_txt TO lwa_objtxt.

APPEND lwa_objtxt TO li_objtxt.

  • Title of the email

lwa_document_data-obj_descr = 'Title of email'.

lwa_document_data-sensitivty = lc_sensitivity.

lwa_document_data-expiry_dat = sy-datum + 15.

lwa_document_data-doc_size = STRLEN( lwa_objtxt ).

lwa_document_data-obj_name = lc_obj_name.

  • e-mail body

CLEAR lwa_objpack.

lwa_objpack-head_start = lc_1.

lwa_objpack-head_num = lc_0.

lwa_objpack-body_start = lc_1.

lwa_objpack-body_num = lc_1.

lwa_objpack-doc_type = lc_raw.

lwa_objpack-doc_size = STRLEN( lwa_objtxt ).

APPEND lwa_objpack TO li_objpack.

  • For e-mail attachment

DESCRIBE TABLE li_attachment LINES l_att_lines.

CLEAR lwa_attachment.

READ TABLE li_attachment INDEX l_att_lines INTO lwa_attachment.

CLEAR lwa_objpack.

lwa_objpack-transf_bin = lc_transf_bin.

lwa_objpack-head_start = lc_1.

lwa_objpack-head_num = lc_1.

lwa_objpack-body_start = lc_1.

lwa_objpack-body_num = l_att_lines.

lwa_objpack-doc_type = lc_raw.

lwa_objpack-obj_name = lc_email.

lwa_objpack-obj_descr = lv_spool_desc.

lwa_objpack-doc_size = ( 255 * ( l_att_lines - 1 ) ) + STRLEN( lwa_attachment-line ).

APPEND lwa_objpack TO li_objpack.

  • make recipient list

CLEAR lwa_reclist.

lwa_reclist-receiver = 'ABC@XYZ.com'. " Email address of your receipient

lwa_reclist-rec_type = lc_ext_id. " To external email id

lwa_reclist-COM_TYPE = 'INT'. " Internet mail

APPEND lwa_reclist TO li_reclist.

  • send mail with attachment

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_document_data

put_in_outbox = lc_outbox

commit_work = 'X'

IMPORTING

sent_to_all = lv_sent_to_all

TABLES

packing_list = li_objpack

contents_bin = li_attachment

contents_txt = li_objtxt

receivers = li_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.

WRITE: 'Success'.

ENDIF.

8 REPLIES 8
Read only

Former Member
0 Likes
851

Hi,

Refer to the below code. It works fine to send emails with text body as well as attachments.

PS: If this solves your question pl mark it answered.

Regards.

_______________________

REPORT zmfv_rough_pad.

DATA :

li_attachment TYPE TABLE OF soli, " hold attachment contents

li_pdf TYPE TABLE OF tline, " hold data from spool in PDF format

li_objpack TYPE TABLE OF sopcklsti1, " hold email body, attachment details

li_objtxt TYPE TABLE OF solisti1, " hold message contents

li_reclist TYPE TABLE OF somlreci1. " hold email reciever details

DATA :

lwa_attachment LIKE LINE OF li_attachment,

lwa_pdf LIKE LINE OF li_pdf,

lwa_objpack LIKE LINE OF li_objpack,

lwa_objtxt LIKE LINE OF li_objtxt,

lwa_reclist LIKE LINE OF li_reclist,

lwa_document_data TYPE sodocchgi1. " hold document details like title, size etc.

*

DATA :

lv_sent_to_all TYPE c, " flag to check if mail is sent to all

l_att_lines TYPE i, " hold number of lines in attachment table

lv_spool_desc(68) TYPE c. " hold description of spool

*

CONSTANTS : lc_email_txt TYPE solisti1-line VALUE 'Find attached Payment Advice sent by this email.',

lc_sensitivity TYPE sodocchgi1-sensitivty VALUE 'O',

lc_raw TYPE sopcklsti1-doc_type VALUE 'RAW',

lc_pdf TYPE sopcklsti1-doc_type VALUE 'PDF',

lc_transf_bin TYPE sopcklsti1-transf_bin VALUE 'X',

lc_email TYPE sopcklsti1-obj_name VALUE 'Email',

lc_ext_id TYPE somlreci1-rec_type VALUE 'U',

lc_outbox TYPE sonv-flag VALUE 'X',

lc_obj_name TYPE sodocchgi1-obj_name VALUE 'Email Test',

lc_1 TYPE n VALUE '1',

lc_0 TYPE n VALUE '0'.

*

CLEAR: lwa_attachment,

lwa_pdf,

lwa_reclist,

lwa_objtxt,

lwa_objpack,

lwa_document_data.

*

REFRESH : li_attachment,

li_pdf,

li_reclist,

li_objtxt,

li_objpack.

  • Build attachment table

lwa_attachment-line = 'YOUR TEXT FROM INTERNAL TABLE LINES'.

APPEND lwa_attachment TO li_attachment.

  • Body of email

CLEAR lwa_objtxt.

MOVE lc_email_txt TO lwa_objtxt.

APPEND lwa_objtxt TO li_objtxt.

  • Title of the email

lwa_document_data-obj_descr = 'Title of email'.

lwa_document_data-sensitivty = lc_sensitivity.

lwa_document_data-expiry_dat = sy-datum + 15.

lwa_document_data-doc_size = STRLEN( lwa_objtxt ).

lwa_document_data-obj_name = lc_obj_name.

  • e-mail body

CLEAR lwa_objpack.

lwa_objpack-head_start = lc_1.

lwa_objpack-head_num = lc_0.

lwa_objpack-body_start = lc_1.

lwa_objpack-body_num = lc_1.

lwa_objpack-doc_type = lc_raw.

lwa_objpack-doc_size = STRLEN( lwa_objtxt ).

APPEND lwa_objpack TO li_objpack.

  • For e-mail attachment

DESCRIBE TABLE li_attachment LINES l_att_lines.

CLEAR lwa_attachment.

READ TABLE li_attachment INDEX l_att_lines INTO lwa_attachment.

CLEAR lwa_objpack.

lwa_objpack-transf_bin = lc_transf_bin.

lwa_objpack-head_start = lc_1.

lwa_objpack-head_num = lc_1.

lwa_objpack-body_start = lc_1.

lwa_objpack-body_num = l_att_lines.

lwa_objpack-doc_type = lc_raw.

lwa_objpack-obj_name = lc_email.

lwa_objpack-obj_descr = lv_spool_desc.

lwa_objpack-doc_size = ( 255 * ( l_att_lines - 1 ) ) + STRLEN( lwa_attachment-line ).

APPEND lwa_objpack TO li_objpack.

  • make recipient list

CLEAR lwa_reclist.

lwa_reclist-receiver = 'ABC@XYZ.com'. " Email address of your receipient

lwa_reclist-rec_type = lc_ext_id. " To external email id

lwa_reclist-COM_TYPE = 'INT'. " Internet mail

APPEND lwa_reclist TO li_reclist.

  • send mail with attachment

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_document_data

put_in_outbox = lc_outbox

commit_work = 'X'

IMPORTING

sent_to_all = lv_sent_to_all

TABLES

packing_list = li_objpack

contents_bin = li_attachment

contents_txt = li_objtxt

receivers = li_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.

WRITE: 'Success'.

ENDIF.

Read only

0 Likes
850

Hi

Our problem is not in the coding level

If we run the program through our network the contents are displaying in pdf attachment,but if the same pgm is executed from the other network the itab contents are displayed as the plain text.

Read only

Former Member
Read only

Former Member
0 Likes
850

Hi,

Look at the below links

<b>sending external email</b>

http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm

<b>Sending mail with attachment</b>

http://www.sap-img.com/abap/sending-email-with-attachment.htm

Regards

Sudheer

Read only

Former Member
0 Likes
850

Yes.. that's right... our problem is not with the coding level...

Read only

0 Likes
850

Check your configuration is the transaction SCOT.

Regards.

Read only

hymavathi_oruganti
Active Contributor
0 Likes
850

REPORT ztest.

  • This example shows how to send

  • - a simple text provided in an internal table of text lines

  • - and an attached MS word document provided in internal table

  • - to some internet email address.

*

  • All activities done via facade CL_BCS!

DATA: send_request TYPE REF TO cl_bcs.

DATA: text TYPE bcsy_text.

DATA: text_xls TYPE bcsy_text.

*data: binary_content type solix_tab.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: bcs_exception type ref to cx_bcs.

data: sent_to_all type os_boolean.

START-OF-SELECTION.

PERFORM main.

----


  • FORM main *

----


FORM main.

try.

  • -------- create persistent send request ------------------------

send_request = cl_bcs=>create_persistent( ).

  • TRY.

.

  • CATCH CX_SEND_REQ_BCS .

  • ENDTRY.

  • -------- create and set document with attachment ---------------

  • create document from internal table with text

APPEND 'Hi! how r u ? open the xls.' TO text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = text

i_length = '12'

i_subject = 'test created by BCS_EXAMPLE_2' ).

  • add attachment to document

  • BCS expects document content here e.g. from document upload

*TRY.

append 'HI' to text_xls.

CALL METHOD DOCUMENT->ADD_ATTACHMENT

EXPORTING

I_ATTACHMENT_TYPE = 'DOC'

I_ATTACHMENT_SUBJECT = 'My attachment'

  • I_ATTACHMENT_SIZE =

  • I_ATTACHMENT_LANGUAGE = SPACE

<b> I_ATT_CONTENT_TEXT = text</b>

  • I_ATT_CONTENT_HEX =

  • I_ATTACHMENT_HEADER =.

.

  • CATCH CX_DOCUMENT_BCS .

*ENDTRY.

  • CALL METHOD document->add_attachment

  • EXPORTING i_attachment_type = 'XLS'

  • i_attachment_subject = 'My Attachment'

  • i_att_content_hex = binary_content.

*

  • add document to send request

CALL METHOD send_request->set_document( document ).

  • --------- set sender -------------------------------------------

  • note: this is necessary only if you want to set the sender

  • different from actual user (SY-UNAME). Otherwise sender is

  • set automatically with actual user.

sender = cl_sapuser_bcs=>create( sy-uname ).

CALL METHOD send_request->set_sender

EXPORTING i_sender = sender.

  • --------- add recipient (e-mail address) -----------------------

  • create recipient - please replace e-mail address !!!

recipient = cl_cam_address_bcs=>create_internet_address(

'hymavathi.oruganti@hp.com' ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

  • ---------- send document ---------------------------------------

CALL METHOD send_request->send(

exporting

i_with_error_screen = 'X'

receiving

result = sent_to_all ).

if sent_to_all = 'X'.

write text-003.

endif.

COMMIT WORK.

  • -----------------------------------------------------------

  • * exception handling

  • -----------------------------------------------------------

  • * replace this very rudimentary exception handling

  • * with your own one !!!

  • -----------------------------------------------------------

catch cx_bcs into bcs_exception.

write: 'Fehler aufgetreten.'(001).

write: 'Fehlertyp:'(002), bcs_exception->error_type.

exit.

endtry.

ENDFORM.

SEE THE ABOVE EXAMPLE, what i bolded is for getting the content

Read only

0 Likes
850

hymavathi..

You had mistaken the requirement..the content of my mail ie. message part in the mail is going / coming as attachment. The pdf format.

I dont want attachment in my mail sending and receiving....

am able to execute successfully in one network..like it is going as a message.. ie body part of mail.. in other network the content goes as a attached format.....

hence in the other network.. what settings needs to be done.. inoder to avoid the attachment format and send it as a normal message...

pls go ahead...