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

Problem in sending email

Subhankar
Active Contributor
0 Likes
911

Hi All,

I want send email from sap program as attachment. The problem is when the attachment any line size is more than 128 then all the value and spaces becomes change to a garbage value.

I am use the function module SO_NEW_DOCUMENT_ATT_SEND_API1.

When we use document type as TXT(wa_objpack-doc_type ) all the characters are come but there is space between each character.

How can I overcome this problem....

Thank & Regards

Subhankar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
863
6 REPLIES 6
Read only

Former Member
0 Likes
864
Read only

Former Member
0 Likes
863

Hi Subhankar

Refer Below Thread

Regards,

SYf

Edited by: syfulla shaik on Aug 14, 2008 1:46 PM

Read only

Former Member
0 Likes
863

Hi,

Please check these links

https://www.sdn.sap.com/irj/sdn/forums

Thanks

Papiya

Read only

Former Member
0 Likes
863

Hi Subhankar

With the email are you attempting to send a text file as an attachment, or are you trying to send another document type (PDF, JPG, XLS, DOC).

I have included an example program below which basically converts a SAPscript output held on the print spool, and formats this for sending via email. This goes into the body of the email.

Commented out are sections for additing email text attachments.

Hope this helps

David Cooper

report zdc_send_attachment .

data: itcpo like itcpo,

tab_lines like sy-tabix.

  • Variables for EMAIL functionality

data: maildata like sodocchgi1.

data: mailpack like sopcklsti1 occurs 2 with header line.

data: mailhead like solisti1 occurs 1 with header line.

data: mailbin like solisti1 occurs 10 with header line.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: solisti1 like solisti1 occurs 0 with header line.

data: g_recip_type(3) type c,

g_memo_purpose(35) type c.

perform send_form_via_email using:

Recip_type Recip_purpose.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

form send_form_via_email using p_recip_type

p_memo_purpose.

clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

concatenate p_recip_type p_memo_purpose into

maildata-obj_descr separated by ' - '.

  • Mail Contents

perform format_contents using:

p_recip_type p_memo_purpose.

mailtxt-line = '----


'.

append mailtxt.

  • Prepare Packing List

perform prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = (external_email)

mailrec-rec_type = 'U'.

append mailrec.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = maildata

put_in_outbox = ' '

tables

packing_list =

mailpack "Packaging of Attached

object_header = mailhead

contents_bin = mailbin "Attachments

contents_txt = mailtxt "Body of Email

receivers = mailrec

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

endform.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

form prepare_packing_list.

clear: mailpack, mailbin, mailhead.

refresh: mailpack, mailbin, mailhead.

describe table mailtxt lines tab_lines.

read table mailtxt index tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

  • Creation of the entry for the compressed document

clear mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

append mailpack.

  • mailhead = 'TEST.TXT'.

  • append mailhead.

    • File 1

  • mailbin = 'This is file 1'.

  • append mailbin.

*

  • describe table mailbin lines tab_lines.

*

  • mailpack-transf_bin = 'X'.

  • mailpack-head_start = 1.

  • mailpack-head_num = 1.

  • mailpack-body_start = 1.

  • mailpack-body_num = tab_lines.

  • mailpack-doc_type = 'TXT'.

  • mailpack-obj_name = 'TEST1'.

  • mailpack-obj_descr = 'Test File 1'.

  • mailpack-doc_size = tab_lines * 255.

  • append mailpack.

*

**File 2

  • mailbin = 'This is file 2'.

  • append mailbin.

*

  • data: start type i.

  • data: end type i.

*

  • start = tab_lines + 1.

*

  • describe table mailbin lines end.

*

  • mailpack-transf_bin = 'X'.

  • mailpack-head_start = 1.

  • mailpack-head_num = 1.

  • mailpack-body_start = start.

  • mailpack-body_num = end.

  • mailpack-doc_type = 'TXT'.

  • mailpack-obj_name = 'TEST2'.

  • mailpack-obj_descr = 'Test File 2'.

  • mailpack-doc_size = tab_lines * 255.

  • append mailpack.

endform.

&----


*& Form format_contents

&----


  • text

----


  • -->P_0104 text

  • -->P_0105 text

----


form format_contents using p_recip_type

p_memo_purpose.

data: lines type standard table of tline with header line.

data: begin of header.

include structure thead.

data: end of header.

data: begin of i_itcpo.

include structure itcpo.

data: end of i_itcpo.

data: begin of i_itcpp.

include structure itcpp.

data: end of i_itcpp.

data: begin of i_rdiresult.

include structure rdiresult.

data: end of i_rdiresult.

data: begin of i_itcoo occurs 0.

include structure itcoo.

data: end of i_itcoo.

data so_ali like soli occurs 100 with header line.

data: desired_type like soodk-objtp.

data: real_type like soodk-objtp.

data: i_spoolid type tsp01_sp0r-rqid_char.

data: sp_lang like tst01-dlang.

g_recip_type = p_recip_type.

g_memo_purpose = p_memo_purpose.

perform format_print_options changing i_itcpo.

*

  • Start Form Processing

*

call function 'OPEN_FORM'

exporting

application = 'TX'

  • archive_index = i_toa_dara

  • archive_params = i_arc_params

device = 'PRINTER'

dialog = ' '

form = 'ZTEST'

language = sy-langu

options = i_itcpo

  • mail_sender = i_mail_sender

  • mail_recipient = i_mail_recipient

  • mail_appl_object = i_mail_appl_object

raw_data_interface = '*'

  • SPONUMIV =

importing

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

result = i_itcpp

exceptions

canceled = 1

device = 2

form = 3

options = 4

unclosed = 5

mail_options = 6

archive_error = 7

invalid_fax_number = 8

more_params_needed_in_batch = 9

spool_error = 10

codepage = 11

others = 12.

*

  • Write each Form Window

*

*MAIN

call function 'WRITE_FORM'

exporting

element = ' '

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

exceptions

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

spool_error = 8

codepage = 9

others = 10.

*

  • Write each Form Window

*

*MAIN

call function 'WRITE_FORM'

exporting

element = ' '

function = 'SET'

type = 'BODY'

window = 'EMAIL'

  • IMPORTING

  • PENDING_LINES =

exceptions

element = 1

function = 2

type = 3

unopened = 4

unstarted = 5

window = 6

bad_pageformat_for_print = 7

spool_error = 8

codepage = 9

others = 10.

call function 'CLOSE_FORM'

importing

result = i_itcpp

rdi_result = i_rdiresult

tables

otfdata = i_itcoo

exceptions

unopened = 1

bad_pageformat_for_print = 2

send_error = 3

spool_error = 4

codepage = 5

others = 6.

refresh so_ali.

call function 'RSPO_RETURN_SPOOLJOB'

exporting

rqident = i_itcpp-tdspoolid "Spool request

first_line = 1 "

last_line = 0 "

desired_type = 'RAW'

importing

real_type = real_type

sp_lang = sp_lang " note 791763

tables

buffer = so_ali

exceptions

no_such_job = 1

job_contains_no_data = 2

selection_empty = 3

no_permission = 4

can_not_access = 5

read_error = 6

type_no_match = 7

others = 8.

loop at so_ali.

mailtxt-line = so_ali.

append mailtxt.

endloop.

i_SPOOLID = i_itcpp-tdspoolid.

call function 'RSPO_R_RDELETE_SPOOLREQ'

exporting

spoolid = i_spoolid

  • IMPORTING

  • RC =

  • STATUS =

  • ERROR_MESSAGE =

.

endform. " format_contents

&----


*& Form format_print_options

&----


  • text

----


  • <--P_I_ITCPO text

----


form format_print_options changing p_itcpo structure itcpo.

"Pages selected for printing

p_itcpo-tdpageslct = ''.

"Number of copies

p_itcpo-tdcopies = 1.

"Spool: Output device

p_itcpo-tddest = 'LOCL'.

"Spool: Device type name

*p_itcpo-TDPRINTER = 'PRINTER'.

"Print preview

p_itcpo-tdpreview = ' '.

"No print preview

p_itcpo-tdnoprev = 'X'.

"No printing from print preview

p_itcpo-tdnoprint = 'X'.

"Print parameters, new spool request

p_itcpo-tdnewid = 'X'.

"Spool request: Name

p_itcpo-tddataset = ''.

"Spool request: Suffix 1

p_itcpo-tdsuffix1 = ''.

"Spool request: Suffix 2

p_itcpo-tdsuffix2 = ''.

"Print parameters, print immediately

p_itcpo-tdimmed = ' '.

"Print parameters, delete after printing

p_itcpo-tddelete = ' '.

"Print parameters, spool retention period

p_itcpo-tdlifetime = ''.

"Send time request

p_itcpo-tdschedule = ''.

"Requested send date

p_itcpo-tdsenddate = ''.

"Requested send time

p_itcpo-tdsendtime = ''.

"Country key

p_itcpo-tdteleland = ''.

"Telecommunications partner

p_itcpo-tdtelenum = ''.

"Title in dialog box

p_itcpo-tdtitle = ''.

"Test form

p_itcpo-tdtest = ''.

"Program name

p_itcpo-tdprogram = ''.

"Screen display position for OTF

p_itcpo-tdscrnpos = ''.

"Print: SAP cover page

p_itcpo-tdcover = ''.

"Print parameters, text for cover page

p_itcpo-tdcovtitle = ''.

"Print parameters, recipient

p_itcpo-tdreceiver = ''.

"Print parameters, department on cover page

p_itcpo-tddivision = ''.

"Print: Authorization

p_itcpo-tdautority = ''.

"Print: Archiving mode

p_itcpo-tdarmod = ''.

"Immediate exit after printing/faxing from print preview

p_itcpo-tdiexit = ''.

"Return of OTF table. No printing, display, or faxing

p_itcpo-tdgetotf = ''.

"SAPoffice user name

p_itcpo-tdfaxuser = ''.

"Spool: Output device

p_itcpo-tdrdidev = ''.

"No changes by user in the archiving mode

p_itcpo-tdnoarmch = ''.

"Spool request completed

p_itcpo-tdfinal = ''.

endform. " format_print_options

Read only

0 Likes
863

Hi All..

I am able to send email as attachment. But my actual problem is that when number of character in each line is more than 128 then garbage values are comes. How could I overcome this...

Read only

0 Likes
863

As long as the text is not longer than 255 characters the contents of mailbin should be able to handle this.

Can you please attache a screen shot of the garbage values that are being presented. Hopefully we can then see what is happening?

Cheers

David Cooper

Edited by: David Cooper on Aug 15, 2008 10:34 AM