Send mails with csv file as an attachment through oracle(SQL SCripts / Stor
Hello Everybody,
I have recently come across a requirement in which I am supposed to send mails with csv file as an attachment through oracle(SQL SCripts / Stored Procedure) .
The contents of the csv file are to be retreived from the Database as well as the content of the mail and to whom it needs to be sent has also to be picked up from the database.
Can somebody suggest me with a suitable code for the same?
Would be of great help..!!
Thanks & Regards,
- VR
Edited by: user646716 on Dec 18, 2009 10:44 AM
read below links
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:255615160805
http://www.orafaq.com/wiki/Send_mail_from_PL/SQL#Send_mail_with_UTL_TCP_-withattachments
How to send csv file as an attachment
Similar Messages
-
Problem with chinese characters while sending mail with .CSV attachment
Hi,
i am sendin .CSV file as an attachment with mail using "SO_DOCUMENT_SEND_API1" FM,
whle opening the mail attachment the chinese characters are not displaying properly.
currently i am using ECC 5.0
can any body help in this regard.
Thanks,
RahimHi Kang Ring,
please convert the content of the attachement into the binary format and then add it as a mail attachment.
LOOP AT i_data ASSIGNING <wa_data>.
if s_output is INITIAL.
CONCATENATE <wa_data> cl_abap_char_utilities=>cr_lf into s_output.
else.
CONCATENATE s_output <wa_data> INTO s_output SEPARATED BY cl_abap_char_utilities=>cr_lf.
endif.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = s_output
IMPORTING
buffer = x_output.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = x_output
TABLES
binary_tab = imail_att.
OR
please use ABAP-Object classes like CL_BCS , CL_document_BCS.....
please findthe below sample code.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = s_output
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
IMPORTING
et_solix = s_output_binary "(of type solix_tab)
ev_size = size ).
attachment->add_attachment( "attachment of type ref to cl_document_bcs
i_attachment_type = 'xls'
i_attachment_subject = l_subject
i_attachment_size = size
i_att_content_hex = s_output_binary ).
you need to write the code for adding the receipents, subject and adding this "attachment " as an attachment to the mail.
Hope this will helps to you....,
thanks,
Rahim. -
Sender "Mail" adapter - CSV file attachment
Hi there
I'm looking for some help in configuring a sender mail adapter that receives ".csv" files. I did read some blogs that mention using the "PayloadSwapBean" module to read the mail attachment instead of the mail content. My problem is to now convert the ".csv" file into a message. Is there a module that I can use ( is it the "MessageTransfomBean" ) and how. Any help would be appreciated.
Thanks
SalilHi Salil,
If you want to send a mail with a body and attachments, the message sender HAS to provide an XI message with attachments. I doubt a CSV file does justice.
As Renjith said you need to convert CSV to XmL.
A short description about the Standard Modules:
MessageTransformationBean is a standard module used to apply the XSLT mapping to the adapter module by using <i>Transform.class</i> ( This xslt mapping is done to create a mail package, Dont confuse with the actual mapping in your case this is NOT for converting csv to xml).
Also this module can be used to change the name and type of payloads by using <i>Transform.contentType</i>, <i>Transform.contentDisposition</i>, <i>Transform.contentDescription</i>.
PayloadSwapbean is a standard module for replacing payloads with other payloads (SWAP)
If you want to give each attachment a certain name use Parameters, <i>swap.keyname</i> for name of the payload and <i>swap.keyvalue</i>.
I Hope the use of standard modules is understood. -
Sending mail with PDF file attachment ?
Hi All,
I have scenario File ---> Mail, monitoring FTP directory for PDF file and sending using mail attachment.
At the moment i am using JAVA mapping to construct the mail package structure follow all the step in this blog : XI Mail Adapter: An approach for sending emails with attachment with help of Java mapping
it is working if i am using text file but then how to encode the pdf content so i can send throught the mail adapter. ?
Thank you and Best Regards
FernandHi,
Actually, i am using this java code below :
try {
// create XML structure of mail package
String output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
+ "<Subject>" + mailSubject + "</Subject>"
+ "<From>" + mailSender + "</From>"
+ "<To>" + mailReceiver + "</To>"
+ "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
+ "<Content>";
out.write(output.getBytes());
// create the declaration of the MIME parts
//First part
output = "--" + boundary + CRLF
+ "Content-Type: text/plain; charset=UTF-8" + CRLF
//+ "Content-Transfer-Encoding: 8bit" + CRLF
+ "Content-Disposition: inline" + CRLF + CRLF
+ mailContent + CRLF
//Second part
+ "--" + boundary + CRLF
+ "Content-Type: Application/pdf; name=" + attachmentName + CRLF
//+ "Content-Transfer-Encoding: base64" + CRLF
+ "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
out.write(output.getBytes());
//Source is taken as attachment
copySource(in, out);
out.write("</Content></ns:Mail>".getBytes());
} catch (IOException e) {
throw new StreamTransformationException(e.getMessage());
protected static void copySource(InputStream in, OutputStream out)
throws IOException {
byte[] bbuf = new byte[in.available()];
int bblen = in.read(bbuf);
if (!(bblen < 0)) {
//String sbuf = new String(bbuf);
//String encoded = Base64.encode(sbuf);
// replace all control characters with escape sequences
//sbuf = sbuf.replaceAll("&", "&");
//sbuf = sbuf.replaceAll("\"", """);
//sbuf = sbuf.replaceAll("'", "'");
//sbuf = sbuf.replaceAll("<", "<");
//sbuf = sbuf.replaceAll(">", ">");
out.write(bbuf);
This code working fine with text file but not for pdf file. because i got error in mail adapter :
Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: com.sap.aii.messaging.util.XMLScanException: java.lang.NullPointerException; nested exception caused by: com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 8f(:main:, row:11, col:4)(:main:, row=11, col=4) -> com.sap.engine.lib.xml.parser.ParserException: Unsupported character: 8f(:main:, row:11, col:4)
I guest the problem because the mail adapter doen't accept pdf content insite the mail package.
please advise me
Best Regards
Fernand -
Send a mail with ppt file as an attachment
Hello,
I need to send an email which has a PPT file as an attachment. The file is on the hard drive of computer. I tried SO_DOCUMENT_REPOSITORY_MANAGER FM. It is asking for a dialog box but I need to design a scheduler which will send this email. Can you suggest any solution(which does not ask for a dialog box)?
Thanks,
Deepti.Hi ,
If your requirement is to send email with attachment by selecting the attachment file from your local hardisk and execute.
and Next, specify the sender email address you can use the following code.
report zmail.
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 -
Sending email with excel file as an attachment
Hi,
In my procedure I am creating one excel file and keeping that excel file in one location as specified in UTL_FILE_DIR.Now my requirement is to pick that excel file from that path and send it as an attachment through an Email.
Can anyone please give me the code to do that and what are the required set up to be done before sending the mail.
Please help me in this regard. This is an urgent requirement.
Thanks
SubhabrataHi,
Please refer the following link:
http://www.dbasupport.com/oracle/ora10g/10g_PLSQL02.shtml
There is para headed Sending E-Mail and Attachments with UTL_MAIL will clarify all your doubts. Link Listing 2.6
is good example.
If you get stuck while coding, get back to us.
Twinkle -
Issue regarding sending E-Mail with PDF file(s) as attachment
Hi,
Can anybody provide me with code to send PDF file as E-Mail Attachment!
I know we have to use F.M <b>SO_NEW_DOCUMENT_ATT_SEND_API1</b> but how we have to use it to send PDF file as attachment!
I was able to send Text files as Attachments in my previous assignments.
Thanks in advance.
Thanks & Regards,
Kumar.Hi,
Check this threads:
SO_NEW_DOCUMENT_ATT_SEND_API1
unable to e-mail a pdf through FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
SO_NEW_DOCUMENT_ATT_SEND_API1
Best regards,
Guillaume
Message was edited by: Guillaume Garcia -
Problem in send mail with .txt file attached
According to the diferent checks, I found the next problems:
1.- Between each caracters there is an space, example:(E Q U I P M E N T) and could be (EQUIPMENT), the last one is the correct form.
2.- For example, two registers in my internal table appear in one line of my .txt file, but i want that each register of my internal table appear in differents lines of my .txt file.
3.- The length of each register of my internal table (objbin) is 255 characters, but i really want that the length of each register of my internal table be 1023 characters.
Thank youThis is my perform:
FORM z_envia_correo .
DATA: docu_data LIKE SODOCCHGI1,
tablines TYPE i,
destinatarios like somlreci1 occurs 1 with header line.
DATA: BEGIN OF packlist OCCURS 0.
INCLUDE STRUCTURE SOPCKLSTI1.
DATA: END OF packlist.
DATA: BEGIN OF objbin OCCURS 0.
INCLUDE STRUCTURE SOLISTI1.
DATA: END OF objbin.
DATA: BEGIN OF object_header OCCURS 0.
INCLUDE STRUCTURE SOLISTI1.
DATA: END OF object_header.
DATA: BEGIN OF contents OCCURS 0.
INCLUDE STRUCTURE SOLISTI1.
DATA: END OF contents.
*-->ihv270907
DATA: l_string TYPE string,
l_fecha(10) TYPE c,
l_dia(2) TYPE c,
l_mes(2) TYPE c,
l_ano(4) TYPE c,
l_hora(8) TYPE c,
l_h(2) TYPE c,
l_min(2) TYPE c,
l_seg(2) TYPE c.
*<--ihv270907
Variable del destinatario para enviar el mail
DATA: l_usrnam TYPE string.
*Caracter salto de linea
FIELD-SYMBOLS <hex_container> TYPE c.
CONSTANTS: zz_tab TYPE x VALUE '0D' LENGTH 4. "valor del salto de linea en hexadecimal
ASSIGN zz_tab TO <hex_container> CASTING.
cargo el texto de cabecera del mail
CLEAR docu_data.
docu_data-obj_name = 'ZFLOTA'.
CONCATENATE 'ZFLOTA' sy-datum INTO docu_data-obj_descr SEPARATED BY space.
docu_data-proc_type = 'T'.
docu_data-proc_name = 'ZFLOTA'.
cargo el texto del cuerpo del mail
CLEAR contents.
*-->ihv270907
l_string = TEXT-I04.
REPLACE '&' IN l_string WITH sy-uname.
l_ano = sy-datum+0(4).
l_mes = sy-datum+4(2).
l_dia = sy-datum+6(2).
CONCATENATE l_dia l_mes l_ano INTO l_fecha SEPARATED BY '/'.
REPLACE '&' IN l_string WITH l_fecha.
l_h = sy-uzeit+0(2).
l_min = sy-uzeit+2(2).
l_seg = sy-uzeit+4(2).
CONCATENATE l_h l_min l_seg INTO l_hora SEPARATED BY ':'.
REPLACE '&' IN l_string WITH l_hora.
contents = l_string.
*<--ihv270907
APPEND contents.
DESCRIBE TABLE contents LINES tablines.
READ TABLE contents INDEX tablines.
docu_data-doc_size = ( tablines - 1 ) * 255 + STRLEN( contents ).
cargo el contenido del attachmet
LOOP AT g_gt_outtab_mail.
g_gt_outtab_mail-line+254(1) = <hex_container>.
MOVE g_gt_outtab_mail-line TO objbin-line.
APPEND objbin.
ENDLOOP.
genero el nombre del archivo a ser attachado
CLEAR object_header.
object_header-line = 'ZFLOTA.txt'.
APPEND object_header.
armo las caracteristicas del mail
CLEAR packlist.
packlist-head_start = 1.
packlist-head_num = 0.
packlist-body_start = 1.
packlist-body_num = tablines.
packlist-transf_bin = space.
packlist-doc_type = 'RAW'.
APPEND packlist.
armo las caracteristicas del attachment
DESCRIBE TABLE objbin LINES tablines.
packlist-transf_bin = 'X'.
packlist-head_start = 1.
packlist-head_num = 0.
packlist-body_start = 1.
packlist-body_num = tablines.
packlist-doc_type = 'TXT'.
packlist-obj_name = 'ZFLOTA.txt'.
packlist-obj_descr = 'ZFLOTA.txt'.
packlist-doc_size = tablines * 250.
APPEND packlist.
Destinatarios
l_usrnam = sy-uname.
MOVE: l_usrnam TO destinatarios-receiver.
destinatarios-rec_type = 'B'. "U externo; B -> SAP
destinatarios-sap_body = 'X'.
APPEND DESTINATARIOS.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = docu_data
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = packlist
OBJECT_HEADER = object_header
CONTENTS_BIN = objbin
CONTENTS_TXT = contents
RECEIVERS = destinatarios
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " z_envia_correo
Thank you. -
How to send mail with zip file
Hi,
We are sending email in one of our program with an attached xls file. We are sending email using classes (cl_bcs).
Our requirement is to send the attached file in zip format to reduce the size.
Please provide if you have any pointers to get zipped file in attachment.
Regards,
MamtaDear Mamta,
Check this class,
CL_ABAP_GZIP -- Class for (De)Compression (GZIP)
CL_ABAP_GZIP_BINARY_STREAM -- Class for Data Compression (GZIP, Streaming)
CL_ABAP_GZIP_TEXT_STREAM -- Class for Text Compression (GZIP, Streaming)
IF_ABAP_GZIP_BINARY_HANDLER -- IF for Output Buffer Handler
IF_ABAP_GZIP_TEXT_HANDLER -- IF for Output Buffer Handler
Regards,
Surjith -
Send Mail with xls AND pdf as attachment
Hi there!
I would lke to write a little program, which is able to send a xls-file AND a pdf-file within one mail.
xls alone is already working fine, I'm using the method add_attachment of the class cl_document_bcs. But now I also want to add a pdf-File to this mail. The pdf file is on the local disk, so I'm uploading it via 'GUI_UPLOAD'. But now I have a problem because I don't know how I am able to add this to the mail.
I hope you can help me!!
Greetings,
littlesamHi,
here a short extract:
DATA: IT_BIN TYPE SOLIX_TAB.
DATA: WA_BIN TYPE SOLIX.
DATA: IT_LENGHT TYPE SO_OBJ_LEN.
DATA: N10(10) TYPE N.
DATA: DOCUMENT TYPE REF TO CL_DOCUMENT_BCS.
DATA: WA_BCS TYPE REF TO CX_BCS.
DATA: ATT_TYPE TYPE SOODK-OBJTP.
DATA: SUBJECT TYPE SO_OBJ_DES.
DATA: P_FILE LIKE RLGRAP-FILENAME VALUE 'C:\TEST.PDF'.
DATA: FILE_NAME TYPE STRING.
DATA: FILE_PATH LIKE PCFILE-PATH.
*UPLOAD
FILE_NAME = P_FILE.
FILE_PATH = P_FILE.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = FILE_NAME
FILETYPE = 'BIN'
CHANGING
DATA_TAB = IT_BIN[].
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
COMPLETE_FILENAME = FILE_PATH
IMPORTING
EXTENSION = ATT_TYPE
NAME = SUBJECT.
* ATTACHMENT
DESCRIBE TABLE IT_BIN LINES N10.
READ TABLE IT_BIN INDEX N10 INTO WA_BIN.
N10 = ( N10 - 1 ) * 255 + STRLEN( WA_BIN ).
IT_LENGHT = N10.
TRY.
CALL METHOD DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = ATT_TYPE
I_ATT_CONTENT_HEX = IT_BIN
I_ATTACHMENT_SIZE = IT_LENGHT
I_ATTACHMENT_SUBJECT = SUBJECT.
* Error abfangen
CATCH CX_BCS INTO WA_BCS.
WRITE: 'Fehler aufgetreten.'(001).
WRITE: 'Fehlertyp:'(002), WA_BCS->ERROR_TYPE.
EXIT.
ENDTRY.
You can use it for every local file
Hope it helps.
regards, Dieter -
Xml file to mail scenario with zip file as an attachment
Hi experts,
I have a file to mail scenario. File is in xml format.
At receiver side, first I want to zip this file and send the zip file as an attachment using mail adapter.
How can i achieve this?
Regards
DiviaHi Shabarish,
In the module tab i have specified the below beans
localejbs/AF_Modules/MessageTransformBean contentType
AF_Modules/PayloadZipBean zip
sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean mail
In the module configuration i mentioned as
Transform.ContentDescription file
Transform.ContentDisposition attachment:filename="file.xml"
zip.filenameKey contentType
zip.mode zipOne
Now i am getting the mail with zip file as an attachment.But the name of the attachment i got is MainDocument.zip
Even the file name inside the zip is MainDocument.xml.
How can i specify my own file name for both zip file and the file inside the archieve folder.Please help me.
Regards
Divia -
How to send the mail with multiple file attachments ?
Sending mails with multiple files as attachments.
You need to start from the app, assuming that it has an email function, that contains the files that you want to send as attachments. The Photos app allows you to send up to 5 photos on the same email, but if you want to send multiple file types then you need an app that supports all those file types. I use the GoodReader app which supports quite a few document/file types (e.g. PDF, Excel, Word, pictures), and from that I can select multiple files (including different types) and attach them to the same email.
-
Convert Script output data to Text(.txt) file & send mail with attachment.
Hi All,
Requirement: I shulb be able to conver th Script output data to Text(.text) file & send a maill with attachment with this text file. Formant of text file should be like output of Print priview.
Plese sugget with Function modules to cover as Text file.
I am able to converting the Script output data to PDF and sending mail with attachment. So I don't want PDF file now.
Thanks in advance.Hi, Thanks for responst.
We can convert the Scirpt output to PDF file by using OTF function module and the PDF file looks like Print Privew output.
Same like this I want Script out in NOTEPAD (.txt). Is that possible, Plz sugget with relavent Function Modules.
Thanks. -
Convert Screen(spool) to PDF file sending mail with attach file
Hi :
I'd like convert spool list to pdf and sending file...
so, I read thread about spool convert to PDF before,
and know how to convert Spool to PDF file and send mail with attach file.
but I have a problem.
my solution as:
step 1. Call function: "CONVERT_ABAPSPOOLJOB_2_PDF"
step 2. Call function: "SO_NEW_DOCUMENT_ATT_SEND_API1"
then, I got a mail with attached PDF file, but the PDF file display limited 255 line.( SO_NEW_DOCUMENT_ATT_SEND_API1 limited)
I want to showing word is wider that 255.
and then I find a manual method as:
After program finished.
Function Menu -> system -> List -> Send
use Prog: "Create Document and Send"
I use this prog sending mail and attached file ,
PDF file do <b>NOT</b> have 255 word limit !
finally. my question is, If I want sending mail as Prog: "Create Document and Send", how to do?
which Function I have to use?...
Please help me, Thanks!Hi,
Check this sample code of sending spool as attachment to an email address..
Parameters.
PARAMETERS: p_email(50) LOWER CASE.
PARAMETERS: p_spool LIKE tsp01-rqident.
Data declarations.
DATA: plist LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: document_data LIKE sodocchgi1.
DATA: so_ali LIKE soli OCCURS 100 WITH HEADER LINE.
DATA: real_type LIKE soodk-objtp.
DATA: sp_lang LIKE tst01-dlang.
DATA: line_size TYPE i VALUE 255.
DATA: v_name LIKE soextreci1-receiver.
DATA rec_tab LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
Get the spool data.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = p_spool
first_line = 1
last_line = 0
desired_type = ' '
IMPORTING
real_type = real_type
sp_lang = sp_lang
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.
IF sy-subrc <> 0.
MESSAGE s208(00) WITH 'Error'.
LEAVE LIST-PROCESSING.
ENDIF.
Prepare the data.
plist-transf_bin = 'X'.
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 0.
plist-body_num = 0.
plist-doc_type = 'RAW'.
plist-obj_descr = 'Test ALV'.
APPEND plist.
plist-transf_bin = 'X'.
plist-head_start = 0.
plist-head_num = 0.
plist-body_start = 1.
DESCRIBE TABLE so_ali LINES plist-body_num.
plist-doc_type = real_type.
Get the size.
READ TABLE so_ali INDEX plist-body_num.
plist-doc_size = ( plist-body_num - 1 ) * line_size
+ STRLEN( so_ali ).
APPEND plist.
Move the receiver address.
MOVE: p_email TO rec_tab-receiver,
'U' TO rec_tab-rec_type.
APPEND rec_tab.
IF NOT sp_lang IS INITIAL.
document_data-obj_langu = sp_lang.
ELSE.
document_data-obj_langu = sy-langu.
ENDIF.
v_name = sy-uname.
Send the email.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
sender_address = v_name
sender_address_type = 'B'
TABLES
packing_list = plist
contents_bin = so_ali
receivers = rec_tab
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.
MESSAGE e208(00) WITH 'Error'.
ENDIF.
COMMIT WORK.
Send the email immediately.
SUBMIT rsconn01
WITH mode = 'INT'
AND RETURN.
Thanks,
Naren -
Send mail with attachment from the uploaded file
hi,
From a form thread i got the following code to send mail with attachment with the file uploaded from the file upload ui element.
public void onActionLoadFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionLoadFile(ServerEvent)
WDWebResourceType FileType = null;
String FileName = new String();
//get attribute info for context attribute 'FileUpload'
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(
IPrivateEmailView.IContextElement.FILE_UPLOAD);
//get modifiable binary type from the attribute info,requires type cast.
IWDModifiableBinaryType binaryType =
(IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();
IPrivateEmailView.IContextElement element =
wdContext.currentContextElement();
//if a file in the 'FileResource' attribute exists
if (element.getFileUpload() != null) {
try {
String mimeType = binaryType.getMimeType().toString();
byte[] file = element.getFileUpload();
//get the size of the uploaded file
element.setFileSize(this.getFileSize(file));
//get the extension of the uploaded file
element.setFileExtension(binaryType.getMimeType().getFileExtension());
//NOTE: context attribute 'FileName' must not be set
//because the FileUpload-UI-element property 'fileName'
//is bound to it. Consequently the fileName is automatically
//written to the context after file upload.
//report success message
wdComponentAPI.getMessageManager().reportMessage(
IMessageEmailComp.SF_UPLOAD,
new Object[] { binaryType.getFileName()},
false);
FileType = binaryType.getMimeType();
FileName = binaryType.getFileName();
} catch (Exception e) {
throw new WDRuntimeException(e);
//if no file in the 'FileResource' attribute exists
else {
//report error message
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportContextAttributeMessage(
element,
attributeInfo,
IMessageEmailComp.NO_FILE,
new Object[] { "" },
true);
//clear the FileResource context value attribute
//element.setFileUpload(null);
String URL;
URL = this.CreateAndGetPathFileUpload(
wdContext.currentContextElement().getFileUpload(),
FileName);
// if (URL.length() == 1){
// //ERRORE
wdContext.currentContextElement().setPATHFileUploaded(URL);
//@@end
public boolean send( java.lang.String subj, java.lang.String mess, java.lang.String dest, java.lang.String attach, java.lang.String FileName )
//@@begin send()
InitialContext ctx = null;
Address[] address = null;
Message msg = null;
Session sess = null;
MimeBodyPart bodyPart = null;
Multipart mp = null;
// "141.29.193.71" == milvl2ja.icn.siemens.it (SMTP di Siemens)
try {
Properties props = new Properties();
props.put("domain","true");
ctx = new InitialContext(props);
sess = (Session) ctx.lookup("java:comp/env/mail/MailSession");
msg = new MimeMessage(sess);
IWDClientUser utente = WDClientUser.getCurrentUser();
String senderEmail = utente.getSAPUser().getEmail();
InternetAddress addressFrom = new InternetAddress(senderEmail);
msg.setFrom(addressFrom);
String EmailDEST = dest;
InternetAddress addressTo = new InternetAddress(EmailDEST);
msg.setRecipient(Message.RecipientType.TO, addressTo);
msg.setSubject(subj);
// if ((mess != null) && (mess.length()>0)) {
// msg.setContent(mess, "text/plain");
// } else {
// msg.setContent("", "text/plain");
//Gestione ATTACHMENT...
String attachedFileName = new String(wdContext.currentContextElement().getFileName());
boolean hasAttachment = (attachedFileName != null) && (attachedFileName.length() > 0);
boolean isMultiPart = (mess != null) && (mess.length() > 1);
//adding an attachment makes the message multipart
if (isMultiPart || hasAttachment) {
mp = new MimeMultipart();
// add text parts
if (mess != null) {
for (int i = 0; i < mess.length(); i++) {
bodyPart = new MimeBodyPart();
bodyPart.setContent(mess,"text/plain");
mp.addBodyPart(bodyPart);
//attach the file to the message if needed
if (hasAttachment) { // avoid the case with no text parts
bodyPart = new MimeBodyPart();
bodyPart.setContent("Allegato incluso nel messaggio.","text/plain");
mp.addBodyPart(bodyPart);
// the part with the file
FileDataSource fds = new FileDataSource(attach);
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setDataHandler(new DataHandler(fds));
//URL URLattachedFileName = new URL(attach);
//attachmentBodyPart.setDataHandler(new DataHandler(URLattachedFileName));
attachmentBodyPart.setFileName(FileName);
mp.addBodyPart(attachmentBodyPart);
msg.setContent(mp);
} else {
if ((mess != null) && (mess.length() > 0)) {
msg.setContent(mess, "text/plain");
} else {
msg.setContent("", "text/plain");
//fine ATTACHMENT
msg.setSentDate(new GregorianCalendar().getTime());
msg.saveChanges();
address = msg.getAllRecipients();
Transport.send(msg, address);
} catch (Exception e) {
e.printStackTrace();
return false;
return true;
//@@end
When i used the same code in my application i am gett ing error in many places..
1)FileDataSource fds = new FileDataSource(<b>attach</b>);
attach cannot be resolved
2)attachmentBodyPart.setFileName(<b>FileName</b>);
fliename cannot be resolved
3)byte[] file = element.getFileUpload();
type mismatch cannot convert sting to byte[]
4)element.setFileSize(this.getFileSize(file));
method getFileSize() is undefined
5)element.setFileExtension(binaryType.getMimeType().getFileExtension());
method getFilExtension() is undefined
6)URL = this.CreateAndGetPathFileUpload(wdContext.currentContextElement().getFileUpload(),FileName);
method CreateAndGetPathFileUpload() is undefined.
7)wdContext.currentContextElement().setPATHFileUploaded(URL);
from the above error i can understand that only i have got the part of the code.
Please send me the complete coding.
some method definitions are missing....
Please help me to send the mail with attachment from the file uploaded from the file upload ui element.
Thanks in advance,
shami.hi,
I got this from the following link
Re: Attaching an excel file
plz help me ...
I am using 2004s with nwds 7.0.06.
also tell me what should be the type of the context variable FileUpload
Thanks in advance,
shami.
Maybe you are looking for
-
Hp officejet pro 8600 doesn't work with yosemite
Dear, I've installed yosemite on my mac and now scanning doesn't work, there isn't the scanning button in system/print and scan like before installing yosemite! I've tried to delete and reinstall driver (also update driver from appstore after install
-
Multiple forms in one region???
Hello guys, I have created application with couple of pages, but now I have one critical issue with one page. In this page I have created multiple forms in one region by customize templated, that is working very much fine, but I unable to insert/upda
-
How many times do i have to submit a report before you fix the damn problem???
Adobe flash player plugin keeps crashing and making me send an error report but never does any help WHATS THE POINT????? if this keeps up im just going to switch back to internet explorer
-
Failed to run simpapp example application of Tuxedo
1. I installed WL9 SP1 on win 2003 machine and Tuxedo 9.1 on this installation 2. I installed the simpapp and follow the instructions at the instructions.html 3. The ant process and ant wtcmbeans process passed successfully 4. When I run the ant run
-
I use iTunes to sort and play my MP3's. Every time I close iTunes my computer slows down to a snails pace for about 2 minutes. I have monitored CPU and memory usage but nothing odd happens during those 2 minutes, and no major hard drive activity happ