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

Sending mail with attachment .....

Former Member
0 Likes
890

Hi Experts,

I have a requirement to send a file as attachment to an enternal user. However the file type can be anything (.BMP,.GIf...) and have to upload that file from application server.

I have already checked out the link

Tried with simple techniques but it works out when i can read the content of the file of the application server. However if the file is Gif or BMP I am clueless how to proceed. Can anyone help please.

Hi Experts,

I have a requirement to send a file as attachment to an enternal user. However the file type can be anything (.BMP,.GIf...) and have to upload that file from application server.

I have already checked out the link

Tried with simple techniques but it works out when i can read the content of the file of the application server. However if the file is Gif or BMP I am clueless how to proceed. Can anyone help please.

5 REPLIES 5
Read only

former_member435013
Active Participant
0 Likes
815

Hi,

with some small changes you can use code like this:

REPORT zsendemail NO STANDARD PAGE HEADING MESSAGE-ID so.

PARAMETERS: fpath(64) LOWER CASE

DEFAULT: 'c:\temp\dummy.txt'.

START-OF-SELECTION.

PERFORM send_test_file USING fpath.

*&----


*& Form send_test_file

*&----


FORM send_test_file USING fpath.

  • create table with binary data from file on server

DATA:

filebindat TYPE solix_tab,

f TYPE x,

i TYPE i,

wa LIKE solix,

size TYPE i.

OPEN DATASET fpath FOR INPUT IN BINARY MODE.

IF NOT sy-subrc IS INITIAL.

RAISE unexpected.

ENDIF.

DO.

IF i = 255.

APPEND wa TO filebindat.

CLEAR: wa, i.

ENDIF.

READ DATASET fpath INTO f.

IF NOT sy-subrc IS INITIAL.

EXIT.

ENDIF.

wa-line+i(1) = f.

size = size + 1.

i = i + 1.

ENDDO.

IF NOT wa IS INITIAL.

APPEND wa TO filebindat.

ENDIF.

CLOSE DATASET fpath.

  • sending

DATA:

attach_size LIKE sood-objlen,

send_request TYPE REF TO cl_bcs,

text TYPE bcsy_text,

document TYPE REF TO cl_document_bcs,

recipient TYPE REF TO if_recipient_bcs,

bcs_exception TYPE REF TO cx_bcs,

sent_to_all TYPE os_boolean.

TRY.

send_request = cl_bcs=>create_persistent( ).

APPEND 'This is a mail with an attachment.' TO text.

APPEND 'It is only for test.' TO text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = text

i_subject = 'e-mail with attachment' ).

attach_size = size.

document->add_attachment( i_attachment_type = 'BIN'

i_attachment_subject = 'test.txt'

i_att_content_hex = filebindat

i_attachment_size = attach_size ).

send_request->set_document( document ).

recipient = cl_cam_address_bcs=>create_internet_address(

'mailadr1<commercial at>domain1.com' ).

send_request->add_recipient( i_recipient = recipient ).

recipient = cl_cam_address_bcs=>create_internet_address(

'mailadr2<commercial at>domain2.com' ).

send_request->add_recipient( i_recipient = recipient ).

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

IF sent_to_all = 'X'.

MESSAGE s022.

ENDIF.

CATCH cx_bcs INTO bcs_exception.

MESSAGE e865 WITH bcs_exception->error_type.

ENDTRY.

COMMIT WORK.

ENDFORM. "send_test_file

Regards

Walter Habich

Read only

Former Member
0 Likes
815

Hi,

Here is the sample code for sending mail with attachment just check this out and do some changes according to ur requirement...

i hope this will help u..

Sending mail with attachment

  • This program will allowed you to send email with attachment.

  • First, specify the attachment file from your local hardisk and execute.

  • Next, specify the sender email address and click the send button.

report y_cr17_mail.

data method1 like sy-ucomm.

data g_user like soudnamei1.

data g_user_data like soudatai1.

data g_owner like soud-usrnam.

data g_receipients like soos1 occurs 0 with header line.

data g_document like sood4 .

data g_header like sood2.

data g_folmam like sofm2.

data g_objcnt like soli occurs 0 with header line.

data g_objhead like soli occurs 0 with header line.

data g_objpara like selc occurs 0 with header line.

data g_objparb like soop1 occurs 0 with header line.

data g_attachments like sood5 occurs 0 with header line.

data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.

data g_ref_document like sood4.

data g_new_parent like soodk.

data: begin of g_files occurs 10 ,

text(4096) type c,

end of g_files.

data : fold_number(12) type c,

fold_yr(2) type c,

fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.

  • Can me any file fromyour pc ....either xls or word or ppt etc ...

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

exporting

user = g_user

  • PREPARE_FOR_FOLDER_ACCESS = ' '

importing

user_data = g_user_data

  • EXCEPTIONS

  • USER_NOT_EXIST = 1

  • PARAMETER_ERROR = 2

  • X_ERROR = 3

  • OTHERS = 4

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

fold_type = g_user_data-outboxfol+0(3).

fold_yr = g_user_data-outboxfol+3(2).

fold_number = g_user_data-outboxfol+5(12).

clear g_files.

refresh : g_objcnt,

g_objhead,

g_objpara,

g_objparb,

g_receipients,

g_attachments,

g_references,

g_files.

method1 = 'SAVE'.

g_document-foltp = fold_type.

g_document-folyr = fold_yr.

g_document-folno = fold_number.

g_document-objtp = g_user_data-object_typ.

*g_document-OBJYR = '27'.

*g_document-OBJNO = '000000002365'.

*g_document-OBJNAM = 'MESSAGE'.

g_document-objdes = 'sap-img.com testing by program'.

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.

g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = sy-uname

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

  • FOLMEM_DATA =

  • RECEIVE_DATA =

.

  • File from the pc to send...

method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.

append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.

g_receipients-recesc = 'B'.

g_receipients-sndex = 'X'.

append g_receipients.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header.

*-- End of Program

Thanks & Regards

Ashu Singh.

Read only

0 Likes
815

Hi,

I have already tried out that option. The problem that comes up is the dialog screen. I dont want that screen but wants to work out my program in background. Any other option you know about.

Read only

0 Likes
815

HI papia kemon acho ?

Read only

0 Likes
815

Hi BLUEFOX,,

I am in real need of the solution so pls dnt use local languages here. My thread may get locked . Please be professional and not regional

Thanks.