Class CL_BCS Query for body part of mail
HI,
I want to send the mail with out attachement using Class CL_BCS. Can any body help me on how to send the message body in the mail using CL_BCS class....
Thanx & Regards,
Sameer
Hi Sameer
I've been struggling with this class CL_BCS too for a while and I want to give my experience with that class. Following a code example which will submit a report to memory and send the report as an attachment by mail thru the SMTP interface.
*& Report ZOBR_SEND_TRIP_SIM_BY_MAIL *
*& This program does following:
*& 1. Submit a travel expense report to memory
*& 2. Read the travel expense report from memory
*& 3. Convert the travel expense report to HTML format
*& 4. Copy the travel expense report from format RAW(1000) to RAW(255)
*& 5. Send an email with body text and attachtments
REPORT zobr_send_trip_sim_by_mail .
DATA:
gi_abaplist TYPE TABLE OF abaplist,
gi_html TYPE w3htmltab,
gs_html LIKE LINE OF gi_html,
gw_string TYPE string,
gw_length TYPE i,
gw_length_c TYPE so_obj_len,
gi_solix TYPE solix_tab,
gs_solix LIKE LINE OF gi_solix,
gi_soli TYPE soli_tab,
gs_soli LIKE LINE OF gi_soli,
go_send_request TYPE REF TO cl_bcs,
go_document TYPE REF TO cl_document_bcs,
go_sender TYPE REF TO cl_sapuser_bcs,
go_recipient TYPE REF TO if_recipient_bcs,
go_exception TYPE REF TO cx_bcs.
* Submit report to memory
SUBMIT rprtef00 "USER sy-uname
EXPORTING LIST TO MEMORY AND RETURN
WITH pnppernr EQ '00001000'
WITH pnptimra EQ 'X'
WITH pnpxabkr EQ 'D2'
WITH pnppabrp EQ '11'
WITH pnppabrj EQ '2006'
WITH s_reisen EQ '0002600221'
WITH hinz_dru EQ space
WITH hinz_weg EQ space
WITH hinz_dyn EQ 'X'
WITH allesdru EQ 'X'
WITH reisepro EQ 'X'
WITH reisetxt EQ 'X'
WITH sw_antrg INCL 'X'
WITH addinfo EQ 'X'
WITH extperio EQ '000'
WITH simulate EQ space
WITH einkopf EQ space.
* Read report from memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = gi_abaplist
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Convert report to HTML format
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
* EXPORTING
* REPORT_NAME =
* TEMPLATE_NAME = 'WEBREPORTING_REPORT'
TABLES
html = gi_html
listobject = gi_abaplist.
LOOP AT gi_html INTO gs_html.
CONCATENATE gw_string
gs_html
INTO gw_string.
ENDLOOP.
gw_length = STRLEN( gw_string ).
gw_length_c = gw_length.
* copy table from format raw(1000) to raw(255)
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = gi_abaplist
out = gi_solix.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
TRY.
* Create persistent send request
go_send_request = cl_bcs=>create_persistent( ).
* Create document (body text in text format)
gs_soli = 'Trip is now settled, see attachment.'.
APPEND gs_soli TO gi_soli.
gs_soli = 'Reimbursement is paid out by your next salary.'.
APPEND gs_soli TO gi_soli.
go_document = cl_document_bcs=>create_document( i_type = 'RAW'
i_text = gi_soli
i_subject = 'Trip reimbursement' ).
* Add attachment (ABAP list format)
CALL METHOD go_document->add_attachment
EXPORTING
i_attachment_type = 'ALI'
i_attachment_subject = 'Expense report(ALI)'
i_att_content_hex = gi_solix.
* Add attachment (HTML format)
CALL METHOD go_document->add_attachment
EXPORTING
i_attachment_type = 'HTM'
i_attachment_subject = 'Expense report(HTM)'
i_att_content_text = gi_html.
* Add note (Text format)
CALL METHOD go_send_request->set_note( gi_soli ).
* Add document to send request
CALL METHOD go_send_request->set_document( go_document ).
* Get sender object
go_sender = cl_sapuser_bcs=>create( sy-uname ).
* Add sender
CALL METHOD go_send_request->set_sender
EXPORTING
i_sender = go_sender.
go_recipient = cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
* Add recipient with its respective attributes to send request
CALL METHOD go_send_request->add_recipient
EXPORTING
i_recipient = go_recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
* set send immediately flag
go_send_request->set_send_immediately( 'X' ).
* Send document
CALL METHOD go_send_request->send( ).
COMMIT WORK.
* Exception handling
CATCH cx_bcs INTO go_exception.
EXIT.
ENDTRY.
Notice that the only way to put a body text in the email is to call the method cl_document_bcs=>create_document with input of a type 'RAW'.
Be aware of the settings of the SMTP node in SAPConnect (transaction SCOT) because the seetings could cource an unwanted conversion of the email.
1. Doubbelclick on the TMTP node and a popup screen will show.
2. Click on the 'Set' button next to 'Internet' under 'Supported address type' and a popup screen will show.
3. Set output format for SAP documents as 'SAPscript/Smart forms' = 'PDF', 'ABAP list' = 'PDF', 'RAW text' = 'TXT'.
This setting will convert 'SAPscript/Smartforms', 'ABAP list' to PDF format. If 'RAW text' = 'PDF' the body text wil be converted to 'PDF' format and change to an attachment and the body text will disappear.
Hope this is usefull for you and others.
Best regards
Ove Bryntesson
Applicon A/S
Similar Messages
-
CLASS cl_bcs Query for sender mail id
Hi,
I am using class cl_bcs.but, i am facing problem for sender mail-id. I want to append mail-id directly to sernder mail-id without using user mail attribute.
Is there ne way from which i can append mail-id as sender mail id??
thanx in advance,
Sameeryou can do that.
check this code sample.
DATA: sender TYPE REF TO if_sender_bcs.
CLEAR sender .
sender = cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
and check this code sample for complete code.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2f9a6165a0
Regards
Raja -
How to place a html page into body part of mail?
Hi,
I want to place a html page into body part of any mail.How can i do this?
Thanks...just set ur message type to text/html and put ur whole html string into the body will do...
-
Cannot Read Body Parts for certain messages on IMAP Server
Hi There
I get the following exception on some (not all) messages when trying to extract and save body parts from an email message on the IMAP server. I can iterate through all the body parts, get the filenames, etc. but when I try to read them I get the following error. Any ideas?
It is MS Exchange (not sure what version) and seems to happen more when there are multiple file attachments or embedded images. We also have a POP3 option and this seems to work fine, only fails when using IMAP...
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
DataHandler dh = bodyPart.getDataHandler();
dh.writeTo(baos); // <=== Exception here
TYPE=TEXT/PLAIN; name="New Text Document.txt"/Disposition=attachment
java.lang.NullPointerException
at com.sun.mail.iap.Response.parse(Response.java:130)
at com.sun.mail.iap.Response.<init>(Response.java:87)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:48)
at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:122)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:230)
at com.sun.mail.iap.Protocol.command(Protocol.java:263)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1234)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1226)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBody(IMAPProtocol.java:994)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBody(IMAPProtocol.java:983)
at com.sun.mail.imap.IMAPBodyPart.getContentStream(IMAPBodyPart.java:169)
at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:94)
at javax.activation.DataHandler.writeTo(DataHandler.java:297)
at com.workpool.interactionservices.EmailMessageUtils.saveBodyPartToFile(EmailMessageUtils.java:250)
at com.workpool.interactionservices.EmailMessageMimeConvertor.processBodyPart(EmailMessageMimeConvertor.java:305)I presume the work around you refer to is to make a copy
of the message? That's all I could find in the FAQ under
IMAP. I'll try that.
Unfortunately the server is sitting with a client on their LAN
and we don't have remote access for debugging. We don't
currently have a way to easily enable debugging for testing.
Getting access for testing can take a few days ... but I shall
do this if the work around does not work. -
Apply color in send mail body part
Hi SAP Gurs,
I am creating program for sending mail to user.. in that mail i so many header and line item are there, i want to apply color or bold, italic format in body part.... so its look like seprate in body part
So is there any possibilty to apply color or bold words in mail body part?
Please help me......
Thanks zeniYou can use the HTML text in the Message body part to get the Colors, Bold, Italics like effect in the mail.
Please refer my answer in this post.
formating possible in sending mail program
Regards,
Naimesh Patel -
How to send a mail to sapuser using class cl_bcs
Hi to all experts,
i have send a mail to local sap user using the class cl_bcs .in the function module we gave reciever type as "B" to send to the local sapuser how to do this in this class cl_bcs.got it
we have to use rml address
recipient = cl_cam_address_bcs=>create_rml_address(
i_syst = sy-sysid
i_client = sy-mandt
i_username = sy-uname ). -
Define attachment name for PDF document using ABAP class CL_BCS
Hi,
I am using the ABAP class CL_BCS to send an email with a PDF attachment. The issue I have is that although I am specifying the attchment name when receiving the email the attachment is called 'MESSAGE'PDF'.
I can view the attachment in SOST and the correct attachment name appears.
I need to use this class as I am sending multiple attachments, whereas the FM only allows 1 attachment .
Has anyone had this issue before with a PDF attachment.
Thanks
MartinHi Hasan,
I have similar requirement. I see your post is pretty old and hope you would have found the solution at that time.
Could you please share it with me?
Thanks
Puneet -
Hello Experts,
I'm tryng to develop my first application for EP (v7 SP12) with NWDS (without NWDI).
This application has to read and write data in the EP DB (oracle v10).
I'm using:
<u>a Dictionary Project</u> (define the DB Tables)
<u>a Java Project</u> (define class as DAO, DBManager etc)
<u>a Library Project</u>
<u>an EJB Project</u>
<u>an EAR Project</u>
With these projects I can deploy a <u>webService</u> in my EP server.
BUT I have some problem with a query that I'm tryng to sent to my DB through a DAO Class called by my WebService.
The query is simple and correct but it does not work...
This is the error message returned (the query id in bold)
(column names: GIORNO, NOMEDITTA, NOMEAREA, NOMESETTORE)
<i>HTTP/1.1 500 Internal Server Error
Connection: close
Server: SAP J2EE Engine/7.00
Content-Type: text/xml; charset=UTF-8
Date: Fri, 21 Sep 2007 14:29:57 GMT
Set-Cookie: <value is hidden>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>java.sql.SQLException: com.sap.sql.log.OpenSQLException: The SQL statement <b>"SELECT NOMESETTORE, MIN(? - "GIORNO") AS GIORNI FROM SRS_DATEINFORTUNI WHERE NOMEDITTA = ? AND NOMEAREA= ? GROUP BY NOMESETTORE ORDER BY NOMESETTORE"</b> <u>contains the syntax error[s]: - 1:25 - the arithmetic expression >>? - "GIORNO"<< contains a host variable (parameter marker)</u></faultstring><detail><ns1:getGiorniSettori_com.akhela.giorniSenzaInfortuni.ejb.exception.GiorniSenzaInfortuniException xmlns:ns1='urn:GiorniSenzaInfortuniWSWsd/GiorniSenzaInfortuniWSVi'></ns1:getGiorniSettori_com.akhela.giorniSenzaInfortuni.ejb.exception.GiorniSenzaInfortuniException></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope></i>
The variable '?' is the today date, the difference <b>"(?-GIORNO)"</b> is an int..
Moreover in my DAO class the query is <b>"SELECT NOMESETTORE, MIN(? - GIORNO) AS GIORNI FROM SRS_DATEINFORTUNI WHERE NOMEDITTA = ? AND NOMEAREA= ? GROUP BY NOMESETTORE ORDER BY NOMESETTORE</b>", instead in the error message is reported <b>MIN(? - "GIORNO")</b>...
We have tryed also with alternative query, for example we used <b>"MIN(SYSDATA - GIORNO)"</b> but <b>SYSDATA</b> was interpreted as column name and not found....
Any help???
Best RegardsHi, I found something about the Host Variable (http://help.sap.com/saphelp_nw70/helpdata/en/ed/dbf8b7823b084f80a6eb7ad43bdbb9/content.htm), there explain that if you want to use an host variable you have to put ':' as prefix..
My problem is that <u>I need to extract the minimum of the subtraction between two dates:</u>
Query <b>MIN(? - GIORNO)</b> --> <i>Error: the arithmetic expression >>? - "GIORNO"<< contains a host variable (parameter marker)</i>
So I tried to use the ':' as indicated in the manual..
<b>MIN:(? - GIORNO)</b> --> - <i>SQL syntax error: the token ":" was not expected here
- expecting LPAREN, found ':'</i>
<b>MIN(:(? - GIORNO))</b> --> <i>- 1:25 - Open SQL syntax error: :PARAMETER not allowed
- 1:26 - SQL syntax error: the token "(" was not expected here
- 1:26 - expecting ID, found '('</i>
Then I tried to avoid the MIN() function and I tried to do just the subtraction:
<b>? - GIORNO</b> --><i> - 1:21 - the arithmetic expression >>? - "GIORNO"<< contains a host variable (parameter marker)</i>
<b>:(? - GIORNO)</b> --> <i>- 1:21 - Open SQL syntax error: :PARAMETER not allowed
- 1:22 - SQL syntax error: the token "(" was not expected here
- 1:22 - expecting ID, found '('</i>
<b>'2007-09-24' - GIORNO</b> --> <i>- 1:34 - SQL syntax error: first argument of operator "-" must be a number, date/time or interval
- 1:43 - SQL syntax error: arguments of operator "-" do not have correct types
- 1:43 - SQL syntax error: derived columns in SELECT list with AS must be values</i>
<b>GIORNO - GIORNO</b> --> <i>- 1:21 - the group by list and the select list are inconsistent: the column >>"GIORNO"<< is neither grouped nor aggregated
- 1:30 - the group by list and the select list are inconsistent: the column >>"GIORNO"<< is neither grouped nor aggregated</i>
Why these parts of query are not accepted???
I don't understand why... I hope you can help me.
Best Regards
Alessandro -
Pdf as in the body of e-mail.
Hello experts,
we are sending a pdf as an attachment of an e-mail.what im trying to do is to send pdf in the body of e-mail.
i have search and couldnt find any help in the documents or discussions.
here is my code:
FORM SEND_MAIL
DATA: lv_formname TYPE tdsfname,
lv_fm_name TYPE rs38l_fnam,
ls_control_parameters TYPE ssfctrlop,
ls_output_options TYPE ssfcompop,
lv_user_settings TYPE tdbool VALUE 'X',
ls_job_output_info TYPE ssfcrescl,
ls_job_output_options TYPE ssfcresop.
DATA: lt_otfdata TYPE TABLE OF itcoo,
lt_pdfdata TYPE TABLE OF tline WITH HEADER LINE.
DATA: ls_data TYPE zfi_s_satici_mutabakat.
DATA: ls_document_data LIKE sodocchgi1,
lv_put_in_outbox LIKE sonv-flag,
lv_sender_address LIKE soextreci1-receiver,
lv_sender_address_type LIKE soextreci1-adr_typ,
lv_commit_work LIKE sonv-flag VALUE space,
lt_packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
lt_object_header TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_contents_bin TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_contents_txt TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_contents_hex TYPE TABLE OF solix WITH HEADER LINE,
lt_object_para TYPE TABLE OF soparai1 WITH HEADER LINE,
lt_object_parb TYPE TABLE OF soparbi1 WITH HEADER LINE,
lt_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE.
DATA: lv_len TYPE i,
lv_pos TYPE i,
lv_tab_lines TYPE i.
DATA: lt_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
CLEAR: lv_formname, lv_fm_name.
lv_formname = 'ZLIMIT_REQUEST_FORM2'.
PERFORM smartform_fm_name USING lv_formname
CHANGING lv_fm_name .
*get PDF Data
ls_control_parameters-getotf = 'X'.
ls_control_parameters-no_dialog = 'X'.
ls_output_options-tdnoprev = 'X'.
LOOP AT itab WHERE sel eq 'X'.
concatenate sy-datum+6(2)'.'sy-datum+4(2)
'.'sy-datum(4) into datum.
CALL FUNCTION lv_fm_name
EXPORTING
control_parameters = ls_control_parameters
output_options = ls_output_options
user_settings = 'X'
datum = datum
EPAYMENT_T1 = EPAYMENT_T1
EPAYMENT_T2 = EPAYMENT_T2
EPAYMENT_D1 = EPAYMENT_D1
EPAYMENT_D2 = EPAYMENT_D2
NAME1 = name1
" itab = itab[]
IMPORTING
job_output_info = ls_job_output_info
TABLES
ITAB = itab
FREE: lt_otfdata, lt_pdfdata.
lt_otfdata[] = ls_job_output_info-otfdata[].
PERFORM convert_otf TABLES lt_otfdata lt_pdfdata.
FREE: lt_receivers, lt_packing_list,
lt_contents_bin, lt_contents_txt.
* Assigning the Description of the object sent in the mail
CLEAR ls_document_data.
ls_document_data-obj_name = 'Limit Talep Formu'.
ls_document_data-obj_descr = 'Limit Talep Formu'.
ls_document_data-expiry_dat = sy-datum + 10.
ls_document_data-sensitivty = 'F'.
LOOP AT gt_mail.
CLEAR : lt_receivers.
lt_receivers-receiver = gt_mail-ZZSAHAMUDUREMAIL. " """reciever list
lt_receivers-rec_type = 'U'.
lt_receivers-com_type = 'INT'.
APPEND lt_receivers.
lt_receivers-COPY = mail_bm.
lt_receivers-rec_type = 'U'.
lt_receivers-com_type = 'INT'.
APPEND lt_receivers.
ENDLOOP.
CLEAR: lt_contents_txt.
lt_contents_txt-line = 'Sayın yetkili,'.
APPEND lt_contents_txt.CLEAR lt_contents_txt.
APPEND lt_contents_txt.
CONCATENATE 'Ekte tarafınıza ait limit formu'
' bulunmaktadır.' INTO lt_contents_txt-line
SEPARATED BY space.
APPEND lt_contents_txt.CLEAR lt_contents_txt.
APPEND lt_contents_txt.
lt_contents_txt-line = 'Saygılarımızla,'.
APPEND lt_contents_txt.CLEAR lt_contents_txt.
CLEAR lt_packing_list.
lt_packing_list-transf_bin = space.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = LINES( lt_contents_txt ).
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list. CLEAR lt_packing_list.
ls_document_data-doc_size = LINES( lt_contents_txt ) * 255.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = lt_pdfdata
content_out = lt_contents_bin
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
*Filling the details in SAPoffice: Description of Imported Object
*Components table
DESCRIBE TABLE lt_contents_bin LINES lv_tab_lines.
CLEAR lt_contents_bin.
READ TABLE lt_contents_bin INDEX lv_tab_lines.
IF sy-subrc = 0.
CLEAR: lt_packing_list.
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lv_tab_lines.
lt_packing_list-obj_langu = sy-langu.
lt_packing_list-doc_type = 'PDF'.
lt_packing_list-obj_name = 'ATTACHMENT'.
lt_packing_list-obj_descr = 'RISK TALEP FORMU.PDF'.
lt_packing_list-doc_size = lv_tab_lines * 255.
APPEND lt_packing_list.CLEAR lt_packing_list.
ENDIF.
lv_put_in_outbox = lv_commit_work = 'X'.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = ls_document_data
put_in_outbox = lv_put_in_outbox
sender_address = lv_sender_address
sender_address_type = lv_sender_address_type
commit_work = lv_commit_work
TABLES
packing_list = lt_packing_list
object_header = lt_object_header
contents_bin = lt_contents_bin
contents_txt = lt_contents_txt
contents_hex = lt_contents_hex
object_para = lt_object_para
object_parb = lt_object_parb
receivers = lt_receivers
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.
* gt_data-gonderx = 'X'.
* modify gt_data.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDLOOP.
ENDFORM. " SEND_MAILHi Matthew Billingham,
i struggled quite a while if i should write a reply or not.
The fact that one of my posts got rejected by suggesting FM SO_DOCUMENT_SEND_API1 finally made me do so. (maybe the rejection was ok for the context i wrote my post for but reading through the forum i feel like some people going to panic if they read the FM-name).
I totally agree with u using CL_BC-Classes instead of old fashioned-FMs for new development.
But that should not lead us in handling the name SO_DOCUMENT_SEND_API1 like they did with the name Lord Voldemort in Harry Potter.
Wanting to display a PDF in email body instead of adding it as attchment, aint nescessary worth a complete redesign of the existing programm - as Cem Unal already posted his code and told us he just want to change it.
As long as there are programms out that use this FM, there will be questions on how to handle this FM no matter if its obsolete or not. And where should they ask, when they wont be able to ask in the scn-forum?
Reading the FMs documentation, there is nothing mentioning this FM is obsolete.
So the strategie of suggesting to use newer technics because of personal preference should (in my opinion) not lead into deleting posts regarding the old technic on the other hand.
regards
Stefan Seeburger -
How to read the message body in a mail
how can we read the message body of a mail. i am using pop3 server for reading the mails. my program is
public class GetMessageExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String username = args[1];
String password = args[2];
Properties props = new Properties();
Session session = Session.getInstance(props, null);
Store store = session.getStore("pop3");
store.connect(host, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + ": " + message.getFrom()[0]
+ "\t" + message[i].getSubject());
System.out.println(
"Do you want to read message? [YES to read/QUIT to end]");
String line = reader.readLine();
if ("YES".equals(line)) {
message[i].writeTo(System.out);
} else if ("QUIT".equals(line)) {
break;
folder.close(false);
store.close();
i am getting the following exception
Exception in thread "main" java.lang.NoSuchFieldError: contentStream
at com.sun.mail.pop3.POP3Message.getContentStream(POP3Message.java:115)
at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSou
rce.java:61)
at com.sun.mail.handlers.text_plain.getContent(text_plain.java:65)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.
java:755)
at javax.activation.DataHandler.getContent(DataHandler.java:511)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1072)The Part interface that the Message class implements describes 3 ways for getting the content of a message. To use an Input Stream, you can call the getInputStream() method on the message itself, rather than System.in.
Hope this helps! -
Hello All,
I am new to javamail api.
The problems, i am encountering are outlined below.
1- First problem which i am encountering is, when i extract the body out of the email, it contains different html tags as well. How can i get rid of these
html tags?
2- Lets say, in my test Gmail account, i had three test emails. Once i read the email body of all three messages and try to
re-run my application, it says, there are no emails in the Gmail inbox. I am unable to understand this concept, so please
help me.
3- Thirdly the disposition is always returned as null, in every case. Why is that?
My code is given below.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import com.datel.email.constants.EmailConstants;
import com.oreilly.networking.javamail.model.EmailBean;
import com.oreilly.networking.javamail.model.ReceiverInformation;
import com.oreilly.networking.javamail.model.SenderInformation;
public class DatelEmailClient {
public static void main(String[] args) throws MessagingException, IOException {
DatelEmailClient emailClient = new DatelEmailClient();
Folder inbox = emailClient.getEmailFolder();
Message[] messages = emailClient.getMessages(inbox);
emailClient.readMessageContent(messages);
public Folder getEmailFolder() throws MessagingException{
Properties prop = new Properties();
prop.setProperty(EmailConstants.IMAP_SOCKET_FACTORY_KEY, EmailConstants.IMAP_SOCKET_FACTORY_VALUE);
prop.setProperty(EmailConstants.IMAP_SOCKET_FACTORY_FALLBACK_KEY, EmailConstants.IMAP_SOCKET_FACTORY_FALLBACK_VALUE);
prop.setProperty(EmailConstants.IMAP_PORT_KEY, EmailConstants.IMAP_PORT_VALUE);
prop.setProperty(EmailConstants.IMAP_SOCKET_FACTORY_PORT_KEY, EmailConstants.IMAP_SOCKET_FACTORY_PORT_VALUE);
prop.put(EmailConstants.IMAP_HOST_KEY, EmailConstants.IMAP_HOST_VALUE);
prop.put(EmailConstants.IMAP_PROTOCOL_KEY, EmailConstants.IMAP_PROTOCOL_VALUE);
prop.put("mail.debug", "true");
Session session = Session.getDefaultInstance(prop);
Store store = session.getStore();
System.out.println("Connecting...");
store.connect(EmailConstants.IMAP_HOST_VALUE, EmailConstants.USER_NAME, EmailConstants.PASSWORD);
System.out.println("Connected...");
Folder inbox = store.getDefaultFolder().getFolder("INBOX");
return inbox;
public Message[] getMessages(Folder inbox) throws MessagingException{
inbox.open(Folder.READ_WRITE);
Message[] msg = inbox.getMessages();
return msg;
public void readMessageContent(Message[] message) throws MessagingException, IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
SenderInformation sender = new SenderInformation();
ReceiverInformation receiver = new ReceiverInformation();
EmailBean emailBean= new EmailBean();
if(message != null){
for(int i = 0; i < message.length; i++){
System.out.println("Subject: " + message.getSubject());
//Reading Email Message Flags
Flags flags2 = message[i].getFlags();
if (flags2.contains(Flags.Flag.ANSWERED)) {
System.out.println("ANSWERED message");
if (flags2.contains(Flags.Flag.DELETED)) {
System.out.println("DELETED message");
if (flags2.contains(Flags.Flag.DRAFT)) {
System.out.println("DRAFT message");
if (flags2.contains(Flags.Flag.FLAGGED)) {
System.out.println("FLAGGED message");
if (flags2.contains(Flags.Flag.RECENT)) {
System.out.println("RECENT message");
if (flags2.contains(Flags.Flag.SEEN)) {
System.out.println("SEEN message");
if (flags2.contains(Flags.Flag.USER)) {
System.out.println("USER message");
* Handling body of the message
Object object = message[i].getContent();
if(object instanceof Multipart){
Multipart multipart = (Multipart) object;
processMultipart(multipart);
System.out.println("Read message? [Y to read / N to end]");
String line = reader.readLine();
if ("Y".equalsIgnoreCase(line)) {
System.out.println("****************************");
else if ("N".equalsIgnoreCase(line)) {
break;
else {
}//for ends here
}//If ends here
}//readMessageContent ends here
public void processMultipart(Multipart multiPart) throws MessagingException, IOException{
System.out.println("Number of parts of Body: " + multiPart.getCount());
System.out.println("Content type of MultiPart is: "+multiPart.getContentType());
for(int i =0 ; i < multiPart.getCount(); i++){
processPart(multiPart.getBodyPart(i));
}//processMultiPart ends here
* @throws MessagingException
* @throws IOException
public void processPart(Part part) throws MessagingException, IOException{
String contentType = part.getContentType();
System.out.println("Content-Type: " + part.getContentType());
if (contentType.toLowerCase( ).startsWith("multipart/")) {
System.out.println("Calling multipart from processPart..");
processMultipart((Multipart) part.getContent( ) );
InputStream io = part.getInputStream();
for(int i= 0;i < io.available(); i++)
System.out.println("I am reading email body..Y");
System.out.print((char)io.read());
//buf.append((char) io.read());
//String output = (char) io.read();
}//main ends here
My constant file is given below
package com.datel.email.constants;
public class EmailConstants {
public static final String IMAP_SOCKET_FACTORY_KEY="mail.imap.socketFactory.class";
public static final String IMAP_SOCKET_FACTORY_VALUE="javax.net.ssl.SSLSocketFactory";
public static final String IMAP_SOCKET_FACTORY_FALLBACK_KEY="mail.imap.socketFactory.fallback";
public static final String IMAP_SOCKET_FACTORY_FALLBACK_VALUE="false";
public static final String IMAP_PORT_KEY="mail.imap.port";
public static final String IMAP_PORT_VALUE="993";
public static final String IMAP_SOCKET_FACTORY_PORT_KEY="mail.imap.socketFactory.port";
public static final String IMAP_SOCKET_FACTORY_PORT_VALUE="993";
public static final String IMAP_HOST_KEY="mail.imap.host";
public static final String IMAP_HOST_VALUE="imap.gmail.com";
public static final String IMAP_PROTOCOL_KEY="mail.store.protocol";
public static final String IMAP_PROTOCOL_VALUE="imap";
public static final String USER_NAME="[email protected]";
public static final String PASSWORD="xxxxx";
Please help me out in the above mentioned queries.
Thanks,
Ben1- First problem which i am encountering is, when i extract the body out of the email, it contains different html tags as well. How can i get rid of these
html tags?By processing the string to remove the tags. If you don't want to have to parse the html yourself,
you can search the web for one of the many html parsing Java libraries. (This isn't really a JavaMail problem.)
2- Lets say, in my test Gmail account, i had three test emails. Once i read the email body of all three messages and try to
re-run my application, it says, there are no emails in the Gmail inbox. I am unable to understand this concept, so please
help me.IMAP or POP3? What are your Gmail settings? Did you read the JavaMail FAQ about connecting to Gmail?
3- Thirdly the disposition is always returned as null, in every case. Why is that?The disposition is optional, so perhaps the sender didn't include it. Or perhaps the server isn't properly
reporting it to the client. Post the protocol trace when accessing a message with no disposition and
post the corresponding MIME content of the message. -
Attach PDF file in class cl_bcs
HI Experts,
I have created a smart form and later on i converted it into a pdf file using CONVERT_OTF Function Module.
Now i have to send it to an external customer for which i m using the functionality of class CL_BCS for sending the email, can any one tell me that how and where can i attach my pdf file while i m using class CL_BCS.
Thanks
Shakun.Hi,
DATA: l_send_request TYPE REF TO cl_bcs, " Send request
l_body TYPE bcsy_text, " Mail body
l_attach TYPE bcsy_text, " Attachment
wa_text TYPE soli, " Work area for attach
l_document TYPE REF TO cl_document_bcs, " Mail body
l_sender TYPE REF TO if_sender_bcs, " Sender address
l_recipient TYPE REF TO if_recipient_bcs, " Recipient
l_email type ad_smtpadr, " Email ID
l_extension type soodk-objtp value 'OTF', " TXT format
l_size TYPE sood-objlen. " Size of Attachment
APPEND 'Test Mail ' TO l_body.
l_attach[] = st_job_output_info-otfdata[].
l_lines = LINES( l_attach ).
l_size = l_lines * 255.
Creates persistent send request
l_send_request = cl_bcs=>create_persistent( ).
Craete document for mail body
l_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_body
i_subject = 'Subject-Here' ).
Add attchment
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = l_extension "'PDF'
i_attachment_subject = 'test_delv'
i_attachment_size = l_size
i_att_content_text = l_attach.
Add the document to send request
CALL METHOD l_send_request->set_document( l_document ).
Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_send_request->set_sender
EXPORTING
i_sender = l_sender.
L_EMAIL = <email_id>.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
Add recipient address to send request
CALL METHOD l_send_request->add_recipient
EXPORTING
i_recipient = l_recipient
i_express = 'X'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).
Send mail
CALL METHOD l_send_request->send( ).
COMMIT WORK.
Regards,
KC -
HI All,
I'm new of this forum but I really hope you could help me solving the problem I have to connect Web Services and midlets.
Somehow my configuration works with some services I've found online but when I invoke very simple services deployed on my server(s) I always have "java.rmi.MarshalException: (1)Missing end tag for Body or Envelope" exception"
Let me add some more information to the problem:
System Configuration:
- JBoss (but I also tried axis) - standard installation (http/1.1)
- WTK 2.5 (but I also tried 2.2) - standard installation
- I tried "trusted" and "untrusted" security configuration of the servlet
- Netbeans IDE 5.0 (to create both Midlets and WS)
- WS uses document/literal as expected by JSR 172
The midlet is created with no problems but at the time of invocation the server throws the above exception (which is part of rmi. remoteException)
By monitoring the network both at client and server side I noticed that the information received is chuncked after 768 bytes. However, If the (soap) reponse is less than such value, I still have the error.
Using Http/1.1. at the mobile side, the service does not return me anything (0kb) while if I set the mobile device to http/1.0, I get the above error.
I really have to make the midlet running so any type of help will be really appreciated!!
Thanks in advanceHi all,
as many developers I have encountered the famous "java.rmi.MarshallException:(1)Missing end tag for Body or Envelope" during the development of my WS app for J2ME (JSR 172).
It is correct that is the empty tag <soapenv:Header /> causing this error.
To fix this error, it is necessary to stop the server to generate this empty header in the response stream.
I have fixed this error for Axis2: unfortunaly it is necessary to modify a class in Axiom library. This library is used in Axis2 to produce the SOAP response, you can download the source code at http://ws.apache.org/commons/axiom/source-repository.html.
Here the class to modify:
axiom\modules\axiom-impl\src\main\java\org\apache\axiom\soap\impl\llom\soap11\SOAP11Factory.java
by commenting the line 273 in the method called getDefaultEnvelope() to prevent the empty header insertion in SOAP response:
public SOAPEnvelope getDefaultEnvelope() throws SOAPProcessingException {
OMNamespace ns =
new OMNamespaceImpl(
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,
SOAP11Constants.SOAP_DEFAULT_NAMESPACE_PREFIX);
SOAPEnvelopeImpl env = new SOAPEnvelopeImpl(ns, this);
//createSOAPHeader(env); the line to be commented
createSOAPBody(env);
return env;
}Finally you have to recompile Axiom using Maven to obtain the fixed package axiom-impl.jar and to replace this package on the lib repository of your Axis2 server.
A little tricky to fix this bug but now my app runs perfectly ;)
Enjoy!
Romain Pellerin
http://www.gasp-mobilegaming.org -
POP3 adapter - Extracting body part
Hi,
I am using POP3 adapter, where I need to extract the body of the mail. and then I need to create xml message keeping this body as one of the fields description.
I am doing this in custom pipeline component. I have working code to create the message, but I am not able extract the body part.
Issue: The email message processing through pipeline, but resulting in empty message output.
I tried keeping break point @ disassemble stage, but control not hitting my code.
I am using below code in disassemble stage to get the body part.
IBaseMessagePart currentPart = pInMsg.GetPartByIndex(0, out partName);
Stream currentPartStream = currentPart.GetOriginalDataStream();
var ms = new MemoryStream();
IBaseMessage outMsg;
outMsg = pc.GetMessageFactory().CreateMessage();
outMsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);
outMsg.Context = pInMsg.Context;
below is the adapter config
Please let me know if any other configurations needs to be done in order to extract the body part
Thanks in advance.Hi,
I am able to debug the code.
In the below code
currentPartStream.CopyTo(ms); is not working in .Net 3.5, how can I replace this code to extract the body part. please help.
CopyTo method works in .net 4.0 and above
public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage
inmsg)
var partName = string.Empty;
// we start from index 1 because index zero contains the body of the message
// which we are not interested
for (int i = 1; i < inmsg.PartCount;
i++)
IBaseMessagePart currentPart = inmsg.GetPartByIndex(i, out partName);
Stream currentPartStream = currentPart.GetOriginalDataStream();
var ms = new MemoryStream();
IBaseMessage outMsg;
outMsg = pc.GetMessageFactory().CreateMessage();
outMsg.AddPart("Body",
pc.GetMessageFactory().CreateMessagePart(), true);
outMsg.Context = inmsg.Context;
currentPartStream.CopyTo(ms);
string attachmentContent = Encoding.UTF8.GetString(ms.ToArray());
MemoryStream attachmentStream = new System.IO.MemoryStream(
System.Text.Encoding.UTF8.GetBytes(attachmentContent));
outMsg.GetPart("Body").Data
= attachmentStream;
outMsg.Context.Write("ReceivedFileName","http://schemas.microsoft.com/BizTalk/2003/file-properties ",
partName);
_msgs.Enqueue(outMsg); -
How can I set body part with byte[]?
Dear all,
I stored image in database (BLOB TYPE).
And I need to send it via e-mail, Can JavaMail set a body part with byte[] that I get it from my database?
If it can be done, how to do that?...I just wonder if the other receive your mail, they cannot know what the mail exactly for....
you should-
1. get the BLOB from database
2. change it to a image file
3. add the file as attachment of your mail with valid content type and Content-Transfer-Encoding
Maybe you are looking for
-
Error in function call when passing timestamp as parameter
Hi All, I have created a function in database "Calulate_Wegs" whcih takes two parameter one "number" and other is "timestamp". I am able to get the output from function when running in database. But when i tries to call the function in OBIEE as EVALU
-
Can I use an external hard drive to install Windows 7 on a macbook
Hi! I currently have a 13" retina macbook pro and want to install windows 7 home premium to use on bootcamp. The problem is that my computer does not have a disk drive. So can I use a desktop to put in the windows disk and download it to an external
-
I've just acquired an Iphone 4s 32gb model. If I take many photos on a trip, which together with the apps already installed, they will soon fill up the memory. What is the best way of storing them till I get home and d/l to my iMac? Is it possible
-
How to make content Pane on JFrame looks like Moving
Hi guys,I have to make a Content Pane look like Race Track which is constantly moving as the cars moves forward.
-
Just installed Safari on my pc and man its nothing close to what apple said it should be, would love to call it slow but that would leave you thinking its faster than it actually is. I know the answer is buy a mac but cant even begin to afford one, m