‎2006 Oct 13 8:14 PM
With this function I have no problem sending the message but the attachment is not sent.
The attachment is in the table mail_bin. Is that correct?
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = mail_title
importing
sent_to_all = sent_to_all
tables
packing_list = mail_pack
object_header = mail_head
contents_bin = mail_bin
contents_txt = mail_txt
receivers = mail_rec
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4.
I'd appreciate any help debugging this problem. How do I know when to get basis involved? This is the first time this company is sending messages to the inbox. Does basis have to set things up.
Thanks.
‎2006 Oct 13 8:48 PM
Here is a sample program which may help. This actually sends a mail with two attachements.
report zrich_0003.
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.
perform send_form_via_email.
************************************************************************
* FORM SEND_FORM_VIA_EMAIL *
************************************************************************
form send_form_via_email.
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
maildata-obj_descr = 'Subject'.
* Mail Contents
mailtxt-line = 'Here is your file'.
append mailtxt.
* Prepare Packing List
perform prepare_packing_list.
* Set recipient - email address here!!!
mailrec-receiver = 'you@yourcompany.com'.
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
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
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 = 'Subject'.
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 = 'Subject'.
mailpack-doc_size = tab_lines * 255.
append mailpack.
endform.
Regards,
Rich Heilman
‎2006 Oct 13 8:37 PM
Hi Janet,
That function is a little tricky.
You could check this program that I use as template when i have to add email capability in my programs.
Regards,
Eric
PD. You also must confirm that the SCOT transaction is working properly in order to ensure that the emails are delivered.
*************************************
*Declarations *
*************************************
REPORT Z_ENVIO_EMAIL_TOP NO STANDARD PAGE HEADING LINE-SIZE 255.
*&----
*
*& Declaración de Tablas *
*&----
*
TABLES: pcfile.
*&----
*
*& Declaración de FIELD-SYMBOLS *
*&----
*
FIELD-SYMBOLS: TYPE STANDARD TABLE.
*&----
*
*& Declaración de Tablas Internas *
*&----
*
DATA:
Declaracion e-mail
it_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
it_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
it_doc_chng LIKE sodocchgi1,
BEGIN OF it_asc_file OCCURS 100,
string TYPE string,
END OF it_asc_file.
*&----
*
*& Declaración de Variables *
*&----
*
DATA:
tab_lines LIKE sy-tabix,
w_drive LIKE pcfile-drive,
w_exte(6) TYPE c,
w_name LIKE sopcklsti1-obj_name,
w_nmex(15) TYPE c,
w_path LIKE pcfile-path,
w_fullpath TYPE string,
w_file LIKE fc03tab-pl00_file,
w_size LIKE scms_acinf-comp_size,
w_rc TYPE i,
w_e_user_stat_intern LIKE jest-stat,
w_e_user_stat_extern LIKE tj02t-txt04,
w_fecha TYPE sy-datum.
*************************************************
*************************************
*Rutines *
*************************************
start-of-selection.
Buscar Destinatarios
PERFORM buscar_destinatarios.
IF NOT it_reclist[] IS INITIAL.
Llenar Correo
PERFORM cuerpo_correo.
Datos Adjuntos
PERFORM datos_adjuntos.
Enviar Correo
PERFORM enviar_correo.
ENDIF.
end-of-selection.
*******************************************************
*&----
*
*& Form buscar_destinatarios
*&----
*
FORM buscar_destinatarios .
******************************************
*
REALIZAR BUSQUEDA DE LOS DESTINATARIOS *
*
******************************************
IF sy-subrc EQ 0.
*----
-
Enviar los distientos email del proveedor
'F' FAX, 'U' mail,'R' RML, 'B' correo SAP
*----
-
* Nombre
* P Lista de distribución personal
* C Lista de distribución general
* O Usuario SAPoffice
* B Usuario SAP
* U Direc.internet
* X Direc.X.400
* R Usuario SAP en otro sistema SAP
A Dirección externa
F Número de fax
D Dirección X.500
L Número de télex
H Unidad organizativa/Posición
J Objeto SAP
G Objeto de organización/ID
1 9 Otros tipos de destinatario
*----
-
LOOP AT it_zqm_dest_qpr.
Usuario Sap
it_reclist-receiver = "nombre del usuario SAP.
it_reclist-rec_type = 'B'.
it_reclist-express = 'X'.
it_reclist-rec_date = sy-datum.
it_reclist-notif_del = ''. " Se espera acuse de recibo
it_reclist-notif_ndel = ''. " Se espera acuse de recibo
APPEND it_reclist.
CLEAR: it_reclist.
Correo Externo
it_reclist-receiver = "Direccion de Email.
it_reclist-rec_type = 'U'.
it_reclist-express = 'X'.
it_reclist-com_type = 'INT'.
APPEND it_reclist.
CLEAR: it_reclist.
ENDLOOP.
ENDIF.
ENDFORM. " buscar_destinatarios
*&----
*
*& Form cuerpo_correo
*&----
*
FORM cuerpo_correo .
TÃtulo del E-Mail
it_doc_chng-obj_name = 'EMAIL'.
it_doc_chng-obj_descr = 'TITULO EMAIL'.
it_doc_chng-obj_langu = 'S'.
it_doc_chng-sensitivty = 'P'.
it_doc_chng-obj_prio = '1'.
it_doc_chng-no_change = 'X'.
it_doc_chng-priority = '1'.
it_doc_chng-obj_expdat = sy-datum + 7. "Expiracion del correo
Contenido del E-Mail
REFRESH: it_objtxt.
CLEAR it_objtxt.
CONCATENATE 'Contenido' 'del correo'
'electronico'
INTO it_objtxt SEPARATED BY space.
APPEND it_objtxt. CLEAR it_objtxt.
APPEND it_objtxt. CLEAR it_objtxt.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
it_doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
it_objpack-transf_bin = space.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = 'RAW'.
APPEND it_objpack.
Se llena la tabla que contendra el archivo adjunto
MOVE it_doc_chng-obj_descr TO it_asc_file-string.
APPEND it_asc_file. CLEAR it_asc_file.
APPEND it_asc_file. CLEAR it_asc_file.
LOOP AT it_objtxt.
MOVE it_objtxt TO it_asc_file-string.
APPEND it_asc_file. CLEAR it_asc_file.
ENDLOOP.
ENDFORM. " cuerpo_correo
*&----
*
*& Form datos_adjuntos
*&----
*
FORM datos_adjuntos .
Se debe generar el archivo a adjuntar
PERFORM generar_archivo.
*----
-
*ALI Doc.ABAPList
*ARC Objeto de archivo (Image)
*BCS Archivo documento externo
*BIN Documento binario
*DLI Lista de distribución
*EXT Doc.PC
*FAX Telefax
*FOL Carpeta
*GRA Gráfico SAP
*OBJ Business object
*OFO Carpeta de objeto
*OTF Documento OTF
*R3I IDOC
*RAW Doc.editor SAP
*SCR Doc.SAPscript
*URL Link a Inter/Intranet
*WIM Work item
*XXL Doc.para Listviewer
DESCRIBE TABLE it_objbin LINES tab_lines.
it_objhead = w_name. APPEND it_objhead.
Creation of the entry for the compressed attachment
it_objpack-transf_bin = 'X'.
it_objpack-head_start = 1.
it_objpack-head_num = 1.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = w_exte.
it_objpack-obj_name = w_name.
it_objpack-obj_descr = w_nmex.
it_objpack-doc_size = tab_lines * 255.
APPEND it_objpack.
ENDFORM. " datos_adjuntos
*&----
*
*& Form generar_archivo
*&----
*
FORM generar_archivo .
Generar el archivo que se va a adjuntar
CLEAR: it_asc_file.
w_fullpath = 'C:Status QPR.xls'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_fullpath
filetype = 'ASC'
write_field_separator = space
TABLES
data_tab = it_asc_file
EXCEPTIONS
file_write_error = 01
no_batch = 04
unknown_error = 05
OTHERS = 99.
CASE sy-subrc.
WHEN 0.
WHEN OTHERS.
MESSAGE i050 RAISING some_error.
ENDCASE.
REFRESH it_asc_file.
Subir el archivo que se va a adjuntar
MOVE w_fullpath TO w_file.
ASSIGN it_objbin[] TO .
CALL FUNCTION 'SCMS_UPLOAD'
EXPORTING
filename = w_file
binary = 'X'
frontend = 'X'
MIMETYPE =
IMPORTING
filesize = w_size
TABLES
data = 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
pcfile-path = w_file.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = pcfile-path
IMPORTING
drive = w_drive
extension = w_exte
name = w_name
name_with_ext = w_nmex
path = w_path
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5.
IF sy-subrc NE 0.
EXIT.
ENDIF.
TRANSLATE w_exte TO UPPER CASE.
TRANSLATE w_name TO UPPER CASE.
Borrar el archivo del disco duro
CALL METHOD cl_gui_frontend_services=>file_delete
EXPORTING
filename = w_fullpath
CHANGING
rc = w_rc
EXCEPTIONS
file_delete_failed = 1
cntl_error = 2
error_no_gui = 3
file_not_found = 4
access_denied = 5
unknown_error = 6
not_supported_by_gui = 7
wrong_parameter = 8
OTHERS = 9.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " generar_archivo
*&----
*
*& Form enviar_correo
*&----
*
FORM enviar_correo .
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = it_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = it_objpack
object_header = it_objhead
contents_bin = it_objbin
contents_txt = it_objtxt
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
receivers = it_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 EQ 0.
WAIT UP TO 2 SECONDS.
Le indicamos al programa de envÃo de correo de SAPCONNECT
que envÃe los correos
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = ''
AND RETURN.
ENDIF.
ENDFORM. " enviar_correo
‎2006 Oct 13 8:44 PM
‎2006 Oct 13 8:48 PM
Here is a sample program which may help. This actually sends a mail with two attachements.
report zrich_0003.
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.
perform send_form_via_email.
************************************************************************
* FORM SEND_FORM_VIA_EMAIL *
************************************************************************
form send_form_via_email.
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
maildata-obj_descr = 'Subject'.
* Mail Contents
mailtxt-line = 'Here is your file'.
append mailtxt.
* Prepare Packing List
perform prepare_packing_list.
* Set recipient - email address here!!!
mailrec-receiver = 'you@yourcompany.com'.
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
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
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 = 'Subject'.
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 = 'Subject'.
mailpack-doc_size = tab_lines * 255.
append mailpack.
endform.
Regards,
Rich Heilman
‎2006 Oct 16 2:39 PM
Rich,
It looks like I am progressing.
Do you know why I would be getting this message when trying to look at the attachment in the inbox?
'Exception Condition ''TABLE_NOT_COMPRESSED' raised'.
Should I use this function on the attachment contents?
call function 'TABLE_COMPRESS'
TABLES
in = listobject
out = compressed_list
EXCEPTIONS
compress_error = 1
OTHERS = 2.
Thanks,
Janet
‎2006 Oct 16 2:57 PM
hi janet,
you are right.
USe this.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
in = listobject
out = objbin
EXCEPTIONS
OTHERS = 1
rgds
anver
pls mark hlpful answers
‎2006 Oct 16 3:20 PM
When I use table_compress, I do not get a runtime error but the attachment is empty. No text shows up.
Any idea what is wrong?
‎2006 Oct 16 3:23 PM
hi,
if so..pls chk this code.
chk this code
DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
&----
*& Form f_send_mail
&----
text
----
--> p1 text
<-- p2 text
----
FORM f_send_mail .
*store the vendor name, vendor email id , employee name and employee
*email id in the internal table int_crb
Creation of the document to be sent
CLEAR doc_chng.
REFRESH objpack.
REFRESH objhead.
REFRESH reclist.
REFRESH objtxt.
File Name
doc_chng-obj_name = 'SHIPMENT'.
<b>* Mail Subject
CONCATENATE 'Shipment Document No.' int_crb_mail-shipdocnum
'Cleared.'
INTO doc_chng-obj_descr SEPARATED BY ' '.
Mail Contents
objtxt-line = 'Hi,'.
APPEND objtxt.
objtxt-line = ' '.
APPEND objtxt.
CONCATENATE 'Shipment Document Number ' int_crb_mail-shipdocnum
' cleared for move.' INTO objtxt-line SEPARATED BY ' '.
APPEND objtxt.
objtxt-line = ' '.
APPEND objtxt.
CLEAR objtxt.
objtxt-line = 'Regards '.
APPEND objtxt.
objtxt-line = ' '.
APPEND objtxt.
objtxt-line = 'SAP '.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN(
objtxt ).
Creation of the entry for the compressed document
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.</b>
Completing the recipient list
target recipent
CLEAR reclist.
reclist-receiver = int_crb_mail-empperid. "employee email ID
"wf_empperid.
reclist-express = 'X'.
reclist-rec_type = 'U'.
APPEND reclist.
copy recipents
CLEAR reclist.
reclist-receiver = int_crb_mail-smtp_addr."vendor email id
reclist-express = 'X'.
reclist-rec_type = 'U'.
reclist-copy = 'X'.
APPEND reclist.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
COMMIT WORK.
SUBMIT rsconn01
WITH mode = 'INT'
WITH output = ' '
AND RETURN.
ENDFORM. " f_send_mail
regards,
anversha.
pls reward points, if this helped u.
‎2006 Oct 13 9:25 PM
Hi Janet,
Yes, you are correct mail_bin is the table that contains the attachment.. just make sure you have prepared the packing list like Rich did in his Program above..
~Suresh
‎2006 Nov 23 12:05 AM
Hello everyone
I did apply all the recommandation mention above.
The only problem I do have is the attachment file is not formatted correctly.
The attachment is an ASCI file read on the applicatoni server that is an Unix machine.
I am using the FM AA_FILE_UPLOAD_TEXTFILE
call function 'AA_FILE_UPLOAD_TEXTFILE'
exporting
I_FILENAME = '/tmp/x'
tables
ET_FILECONTENT = mailbin.
Mailbin contain exacly the file. Each records are starting at the first position.
Mailbin
1 First line
2 Second line
3 third line
But when I am openning the attachtment from the email, I do obtain:
First line
.............Second line
...............................third line
Is there any way to add 'returns' at the end of each line to be able to read the attachment in windows?
Regards