Urgently need EwsJavaApi example to read email from exchange, and print text attachment to file.
Hello,
I have the below code running using the EwsJavaApi. I need to modify it to read the the first email that matches the search string, and then save it's attachment to a file.... Thank you in advance!!!
public class EWSDemo {
* @param args
public static void main(String[] args) throws Exception {
ExchangeService service = new ExchangeService();
// Provide Crendentials
ExchangeCredentials credentials = new WebCredentials("[email protected]", "yubbybuddy");
service.setCredentials(credentials);
// Set Exchange WebSevice URL
service.setUrl(new URI("https://outlook.office365.com/EWS/exchange.asmx"));
// Get five items from mail box
ItemView view = new ItemView(5);
// Search Inbox
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox,"Subject:ROGERDODGER123", view);
// iterate thru items
for (Item item : findResults.getItems()) {
System.out.println(item.getSubject());
AttachmentCollection myAttachments = item.getAttachments();
System.out.println(myAttachments.);
>> I need to modify it to read the the first email that matches the search string
By first do you mean then newest email to arrive or the oldest email in the Mailbox that matches that string ?
Exchange returns Items from Newest to oldest by default if you want the older messages then you can use the OrderBy property
http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.itemview.orderby(v=exchg.80).aspx which should give you the oldest item
Cheers
Glen
Similar Messages
-
Need to read Email from Lotusnotes and Outlook using Oracle
Dear All,
My database version Oracle 10.2
I need to read Email from Lotusnotes and Outlook using Oracle.
I have tried with below link
http://sourceforge.net/projects/plsqlmailclient/The problem is i am getting some java error.
Can anyone suggest me to proceed further.
Cheers,
SanI am using the another function to read an email from pop3 server
create or replace
FUNCTION pop3 (
username VARCHAR2,
PASSWORD VARCHAR2,
msgnum NUMBER
RETURN tstrings PIPELINED
IS
--POP3_SERVER constant varchar2(19) := '127.0.0.1';
pop3_server CONSTANT VARCHAR2 (100) := 'xxxxxx';
pop3_port CONSTANT NUMBER := 110;
--POP3_TIMEOUT constant number := 10;
pop3_ok CONSTANT VARCHAR2 (10) := '+OK';
e_pop3_error EXCEPTION;
--E_READ_TIMEOUT exception;
--pragma exception_init( E_READ_TIMEOUT, -29276 );
socket UTL_TCP.connection;
line VARCHAR2 (30000);
BYTES INTEGER;
-- send a POP3 command
-- (we expect each command to respond with a +OK)
FUNCTION writetopop (command VARCHAR2)
RETURN VARCHAR2
IS
len INTEGER;
resp VARCHAR2 (30000);
BEGIN
len := UTL_TCP.write_line (socket, command);
UTL_TCP.FLUSH (socket);
-- using a hack to check the popd response
len := UTL_TCP.read_line (socket, resp);
IF SUBSTR (resp, 1, 3) != pop3_ok
THEN
RAISE e_pop3_error;
END IF;
RETURN (resp);
END;
BEGIN
--UTL_TCP.CLOSE_CONNECTION (SOCKET);
PIPE ROW ('pop3:' || pop3_server || ' port:' || pop3_port);
-- Just to make sure there are no previously opened connections
UTL_TCP.close_all_connections;
-- open a socket connection to the POP3 server
socket :=
UTL_TCP.open_connection (remote_host => pop3_server,
remote_port => pop3_port,
--tx_timeout => POP3_TIMEOUT,
CHARSET => 'US7ASCII'
-- read the server banner/response from the pop3 daemon
PIPE ROW (UTL_TCP.get_line (socket));
-- authenticate with the POP3 server using the USER and PASS commands
PIPE ROW ('USER ' || username);
PIPE ROW (writetopop ('USER ' || username));
PIPE ROW ('PASS ' || PASSWORD);
PIPE ROW (writetopop ('PASS ' || PASSWORD));
-- retrieve the specific message
PIPE ROW ('RETR ' || msgnum);
PIPE ROW (writetopop ('RETR ' || msgnum));
--PIPE ROW( 'LIST '||msgNum ); PIPE ROW( WriteToPop('LIST '||msgNum) );
PIPE ROW ('*** START OF INTERNET MESSAGE BODY ***');
LOOP
dbms_output.put_line('entering');
BYTES := UTL_TCP.available (socket);
IF BYTES > 0
THEN
BYTES := UTL_TCP.read_line (socket, line);
line := REPLACE (line, CHR (13) || CHR (10), '');
-- WILL HAVE TO USE PLSQL FUNCTIONS (HAVE BOOKMARKED) TO GET THE MAIL
-- IN THE PREFERRED FORMAT. CAN USE "REPLACE()"
IF LENGTH (line) = 1 AND line = '.'
THEN
PIPE ROW ('*** END OF INTERNET MESSAGE BODY ***');
ELSE
PIPE ROW (line);
end if;
END IF;
EXIT when length (LINE) = 1 and LINE = '.';
-- PIPE ROW (line);
END LOOP;
--PIPE ROW( '*** END OF INTERNET MESSAGE BODY ***' );
-- close connection
PIPE ROW ('QUIT');
PIPE ROW (writetopop ('QUIT'));
UTL_TCP.CLOSE_CONNECTION (SOCKET);
EXCEPTION
WHEN e_pop3_error
THEN
PIPE ROW ('There are no mails !');
END;I am getting the below output .
21 pop3:sbssld1 port:110
75 "+OK Lotus Notes POP3 server version Release 8.0.1 ready on SBSSLD1/SBPSS.
47 USER [email protected]
69 "+OK [email protected], your papers please.
13 PASS password
63 "+OK [email protected] has 1 message.
6 RETR 1
17 "+OK 1546 octets
38 *** START OF INTERNET MESSAGE BODY ***
9 Subject:
48 X-KeepSent: A231D6D0:8485FE4B-65257AB1:0022E60F;
23 type=4; name=$KeepSent
46 To: [email protected]
53 X-Mailer: Lotus Notes Release 8.0.1 February 07, 2008
95 Message-ID: <[email protected]mbnpparibasfs.in>
48 From: [email protected]
36 Date: Fri, 9 Nov 2012 11:51:14 +0530
90 X-MIMETrack: Serialize by POP3 Server on SBSSLD1/SBPSS(Release 8.0.1|February 07, 2008) at
23 11/09/2012 11:51:21 AM
17 MIME-Version: 1.0
37 Content-type: multipart/alternative;
68 " Boundary="0__=EABBF022DFB16ED68f9e8a93df938690918cEABBF022DFB16ED6""
27 Content-Disposition: inline
(null) (null)
58 --0__=EABBF022DFB16ED68f9e8a93df938690918cEABBF022DFB16ED6
39 Content-type: text/plain; charset=UTF-8
33 Content-transfer-encoding: base64
(null) (null)
(null) (null)
76 DQoNCg0KUmVnYXJkcywNClNoYW5tdWdhbSBOYXRhcmFqYW4uDQpNb2IgOiA5NjI5MjUyNDI1DQpP
76 ZmYgOiAwNDQgMjI1MDQ3MDAgRXh0biA0Nzc5DQoNCiB+SWYgdGhlIGZhY3RzIGRvbuKAmXQgZml0
68 IHRoZSB0aGVvcnksIGNoYW5nZSB0aGUgZmFjdHMu4oCdIC0gQWxiZXJ0IEVpbnN0ZWlu
(null) (null)
58 --0__=EABBF022DFB16ED68f9e8a93df938690918cEABBF022DFB16ED6
38 Content-type: text/html; charset=UTF-8
27 Content-Disposition: inline
33 Content-transfer-encoding: base64
(null) (null)
76 PGh0bWw+PGJvZHk+DQo8cD5SZWdhcmRzLDxicj4NClNoYW5tdWdhbSBOYXRhcmFqYW4uPGJyPg0K
76 TW9iIDogOTYyOTI1MjQyNTxicj4NCk9mZiA6IDA0NCAyMjUwNDcwMCBFeHRuIDQ3Nzk8YnI+DQo8
76 YnI+DQogfklmIHRoZSBmYWN0cyBkb27igJl0IGZpdCB0aGUgdGhlb3J5LCBjaGFuZ2UgdGhlIGZh
60 Y3RzLuKAnSAtIEFsYmVydCBFaW5zdGVpbjxicj4NCjwvYm9keT48L2h0bWw+
(null) (null)
60 --0__=EABBF022DFB16ED68f9e8a93df938690918cEABBF022DFB16ED6--
(null) (null)
36 *** END OF INTERNET MESSAGE BODY ***
4 QUIT
42 "+OK Lotus Notes POP3 server signing off.
"Now pls suggest me how can i store the sender mail id, receiver mail id, subject and body of the mail in a table.
So that i can display the saved data in the above table as a mail in my separate application.
Thanks in advance.
Cheers,
San -
How can I permantely delete email information from my iphone4?
I deleted all my emails from inbox and trash, but the Mail "file" still has 2GB...Does anyone have an answer to this problem? It's been 4 or 5 days now and iCloud still says I have 0kb of 5GB available, and 6.1GB of mail on iCloud. I guess that's better than yesterday when it said I had 8.3GB of mail. Does anyone know if it simply takes Apple a week to actually empty a mailbox?
thanks in advance, hopefully tomorrow it says I have only 4GB of non-existent mail and I can start using it again... -
Reading data from table and print the value based condition
hi
my table like this
slno | value1 | value2 |
1 0 5
2 5 10
3 10 15
assume n= 8 ( where n is user define)
i want output like
number 8 between value 5 and 10
plz helpHi,
Try:
Select 'Number '+ U_Value3 + ' Between '+ U_Value1'and 'U_Value2
From [dbo\].[@UDT T0\]
Where T0.U_Value3=[%0\] and T0.U_Value3 BETWEEN U_Value1 AND U_Value2
Thanks,
Gordon -
Read email from microsoft exchangeserver 2010 and save attachement
Hello,
I want to read email from microsoft exchangeserver 2010 and save attachement into a folder.I created an Java program to import attachments from a exchange server mailbox using "POP3S".It works fine when run as a java application.But when i put this inside Oracle11g R2 using load java and while executing from a procedure it gives an error at parsing message into Multipart
Error at line : Multipart mp = (Multipart)m.getContent();
Error:
Content-Type: multipart/mixed;
boundary="_002_A0C2E09A..................................."
java.lang.ClassCastException
at mailPop3.checkmail(mailPop3:71)
My Java Class is as follows,
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
The function i used to check for attachments is given below.
public static boolean hasAttachments(Message m) throws java.io.IOException, MessagingException
Boolean hasAttachments = false;
try
// if it is a plain/html text - no attachements
if (m.isMimeType("text/*"))
return hasAttachments;
else if (m.isMimeType("multipart/alternative"))
return hasAttachments;
else if (m.isMimeType("multipart/*"))
Multipart mp = (Multipart)m.getContent();
if (mp.getCount() > 1)
hasAttachments = true;
return hasAttachments;
catch (Exception e) {
e.printStackTrace();
} finally {
return hasAttachments;
My Java Details as follows
java Version :1.5.0_10
java.vm.specification.version:1.0
java.vm.version :1.5.0_01
java.specification.version:1.5
java.class.version:48.0
Java mail API:javamail-1.4.4
Used Jars:mail.jar
Could someone explain why I am getting this error? What can I do to resolve this error?
Is any other Jar need other than mail.jar?
Any help would be much appreciated.
Regards,
Nisanth889509 wrote:
This java class has no error.Then it should work - not only at compile time, but at run-time too.
Because it does not, it means there are errors. And as the error you've posted is not an Oracle SQL or PL/SQL error, your question is off-topic to this forum.
Why would the code not work at run-time? Numerous reasons, including environmental ones. Java inside Oracle are subjected to a number of restrictions and limitations that do not exist in a Java VM outside Oracle (for good reasons).
So you need to consider that too - and that is why I referred you to the documentation... which is IMO mandatory reading for all Oracle developers. -
I used my military (.mil) address as the backup for my appleID account, but now that I need to open the verification email from apple, the .mil doesnt allow me to open and verify that I am who I am?
Hey Edgew7,
Thanks for the question. The following resource may provide a solution:
iOS 7: If you're asked for the password to your previous Apple ID when signing out of iCloud
http://support.apple.com/kb/ts5223
3. Change your Apple ID temporarily
If signing out and back in to iMessage or FaceTime didn't work, try these steps:
1. Change your Apple ID to the Apple ID you used previously. You shouldn't need to verify the email address.
2. Tap Settings > iCloud and try to sign out.
3. Change your Apple ID to the new email address that you want to use. You'll need to verify the email address.
4. Tap Settings > iCloud and sign in with the new Apple ID.
Thanks,
Matt M. -
Reading emails from gmail by labview
I easily found a sample program to send an email to Gmail in LabVIEW and it works well. But I want to read emails from Gmail in LabVIEW as well. Is this possible? Thanks
Jay
Solved!
Go to Solution.Well, not so much a duplicate post, since that post was asking about reading attachments. This is asking about getting emails from Gmail.
To OP: Your question is not clear. Are you trying to download emails from your Gmail account? If so, you first need to configure Gmail to turn on the POP service. I don't think this is enabled by default. The Gmail help documents tell you how to do this. Once you've done that, you can just use a POP client. You can start by trying the one posted in this thread, but be aware, that sometimes servers have their own little "quirks", as alluded to in that thread. -
I can not count the data from the module. Can prompt as it to make. It is desirable with examples (data read-out from the module and data transmission between channels. It is in advance grateful.
Hello. Most of the engineers in developer exchange are more familiar
with NI products. Contacting ICS for technical support is a better
course of action. -
Reading emails from Faxcom server with javamail 1.4.2
Our JavaMail-based application reads up to 60,000 emails a day. We recently upgraded to JavaMail 1.4.2 to get more leniency reading poorly formatted messages. So far, it's looking great. We only experienced one issue. Upon upgrading, we stopped being able to receive multiparts sent via Faxcom product. To resolve this, we set the property:
mail.mime.multipart.ignoreexistingboundaryparameterto "false". If it is set to true, it will not be able to read emails from the Faxcom product that were previously successful using JavaMail 1.4.1. Basically, the API returns zero for the multipart count. If you are setting some of the new leniency parameters, I would recommend keeping this "false" unless it solves some specific problem.
Just wanted to post this to see if anyone had experienced the same problem, and to share the solution.Thanks Bill, I will try setup a simple program to reproduce, or see if I can reproduce with one of the JavaMail sample programs - I also have a FaxCom mailbox setup for testing.
We are also still having trouble consuming a few messages that have a broken Content Type field:
08:37:05.996 INFO: (EmailServer.processMultipart-Thread-21) Inside Content Type: text/plain
name="incoming.txt"
javax.mail.internet.ParseException: Expected ';', got "NAME"
at javax.mail.internet.ParameterList.<init>(ParameterList.java:280)
at javax.mail.internet.ContentType.<init>(ContentType.java:110)
...etc..
I will also look and find out which mail client that came from. Maybe the solution here is trying to ask the sender to fix/upgrade/switch mail clients.
But other than these 2 occasional problems, 1.4.2 is working great in production and we are getting a lot fewer failures. -
Getting error "The response received from the service didn't contain valid XML." with inner exception "dtd is prohibited in this xml document exchange" while reading emails from outlook(Not while reading every mail).
Can anybody please tell me what might be the issue. Below is the code where I am getting error
FindItemsResults<Item> RetrievedItems=null ;
RetrievedItems = service.FindItems(FIds, new ItemView(4));
String[] SignatureList = ConfigurationManager.AppSettings.Get("SignatureTypes").Split(',');
if (RetrievedItems != null && RetrievedItems.Count() > 0)
RetrievedItems.ToList().ForEach(x =>
try
List<String> Attachments = new List<String>();
List<String> ScanFileName = new List<String>();
bool IsAvailable = true;
//Getting error while Load() - below line of code
((Microsoft.Exchange.WebServices.Data.EmailMessage)x).Load();
Vo.EmailMessage msg = new Vo.EmailMessage();
msg.MessageId = ((Microsoft.Exchange.WebServices.Data.EmailMessage)x).Id.UniqueId;
msg.From = ((Microsoft.Exchange.WebServices.Data.EmailMessage)x).From.Address;
((Microsoft.Exchange.WebServices.Data.EmailMessage)x).ToRecipients.ToList().ForEach(z => msg.To += z.Address + ",");
((Microsoft.Exchange.WebServices.Data.EmailMessage)x).ReplyTo.ToList().ForEach(y => msg.ReplyToEmailAddress += y.Address + ",");
msg.Subject = ((Microsoft.Exchange.WebServices.Data.EmailMessage)x).Subject;
msg.Body = ((Microsoft.Exchange.WebServices.Data.EmailMessage)x).Body.Text;
msg.Dated = ((Microsoft.Exchange.WebServices.Data.EmailMessage)x).DateTimeSent;
Please help.Hi,
Thank you for your post.
This is a quick note to let you know that we are performing research on this issue.
Niko Cheng
TechNet Community Support -
Why "Outlook Express" users can't read email from Mail.app ?
Why "Outlook Express" users can't read email from Mail.app ? Any explanation ? Select a good format,that's a good explanation,but i can't know each time if our recipients use "Outlook Express".
There are no completely bug free email clients including the Mail.app and Outlook has its share of bugs for such an old/mature email clients and some glaring ones that MS has been aware of for a long time but has chosen not to do anything about since these do not affect exchanging email with other Outlook users.
Outlook has always had problems with Mail's RTF and the degree depending on the Windows and Outlook versions used by the recipient.
Check this link.
http://homepage.mac.com/thgewecke/woutlook.html -
How to read emails from Microsoft Exchange Server
I have microsoft exchange server and I want to read emails from microsoft exchange server. There is no POP3 server. So is it possible?
If it is possible to read emails from microsoft exchange server then please give me some idea.
Thanks
Santanusantanu wrote:
Hi,
My company is using Microsoft exchange server.
IMPA and POP3 has been disabled, but my requirement is I wan to read email.Then ask the administrator of the server to enable IMAP. If you have a valid business requirement to do that, there would be no reason for the administrator to refuse. -
Read email from multiple machines
Hi, I have an intel macbook and imac and am looking for an efficient way to read email from both machines. I currently use POP and have to check both machines to be sure I don't miss any mail. Is there a simple way of making the imac an IMAP mail server and use the macbook to read only?
If you set up an IMAP email account, you can read, send and delete your mail on any mac, which has your IMAP account set up. Because all your mail data etc is stored on the server, not on your computer. Think of it as a form of "web mail" but accessible through your email program (Mail and Entourage)
Cheers -
Conditional Routing of emails from Exchange 2007
I have a requirement to be able to control the routing of emails from Exchange 2007 based upon the sender email address.
For example, an exchange 2007 email system has 2 accepted domains, domain1.com and domain2.com. The system uses 2 external SMTP gateways used for sending all outbound email (gateway1 & gateway2)
If [email protected] emails [email protected] I want it to travel via gateway1
If [email protected] emails [email protected] I want it to travel via gateway2.
All mailboxes are on a single mailbox server cluster, and there are 2 load balanced Hub Transport servers.
I have looked into various ways of dealing with this and have had no success. I looked at transport rules, but I dont believe it is possible to specify the next hop. I've also looked into setting permissions on the send connectors, but it is not clear exactly what permissions I need to set, or whether it will work.
The only solution I can see is to forward all outbound emails to a separate SMTP gateway (such as postfix) which supports this kind of functionality. However I would rather solve the problem using Exchange.
Any suggestions?This is not possible natively in Exchange but you can create your own transport agent and hook it with Exchange to configure conditional routing. You may try posting a query in Development forum to get help from developers on writing a transport agent.
http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads
Here is a great step-by-step example in that direction, not exactly what you are looking for but quite similar to that...
How to control routing from your own routing agent
http://blogs.technet.com/appssrv/archive/2009/08/26/how-to-control-routing-from-your-own-routing-agent.aspx
Amit Tank | MVP – Exchange Server | MCITP: EMA | MCSA: M | http://ExchangeShare.WordPress.com -
Read header text from vf01 and print in script main window
Hi Gurus,
I need to read text from vf01 header note 1, there user type max 10 lines i want to read that 10 lines and print in sap script main window after line item printed. i used read text but one line only fetched. i declare variable like data : NEXRSP LIKE TLINE-TDLINE and read_text function module. pls provide solution for this.
Regards
G.VendhanHI GURUS,
Thank u for reply i declare like
ID = '0002'.
PERFORM READTEXT USING EN NAME OBJECT ID TEXT_OUTPUT.
NEXRSP = TEXT_OUTPUT . CLEAR TEXT_OUTPUT.
FORM READTEXT USING P_EN
P_NAME
P_OBJECT
P_ID
P_TEXT_OUTPUT.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = P_ID
LANGUAGE = P_EN
NAME = P_NAME
OBJECT = P_OBJECT
TABLES
LINES = LINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
LOOP AT LINES.
P_TEXT_OUTPUT = LINES-TDLINE.
EXIT.
ENDLOOP.
FREE LINES. CLEAR LINES.
ENDFORM. " READTEXT
Maybe you are looking for
-
How do I get usb superdrive to work with new macbook pro. superdrive rejects cd ?
Just purchased new system. (never had an apple before) so I am all at sea. followed the instructions to uodate the system. whenI inserted a cd with program to be installes foe a Mac, it was ejected. inserted a cd with 'jpeg files only on it it too wa
-
Hi All, Iam new to these kind of programs. have to put check boxes and text boxes in the list and then save it. for example if 10 materials are displayed. for each material have to put check box and text box. if check box is checked and save button
-
BPM BADI_BUILD_MESSAGE
Hi colleagues, Have anyone used this BAdI(BADI_BUILD_MESSAGE) in order to change the BPM notification content? I'd apreciate if you could give me any tips on how to implement it. best regards, Matías Krsanac
-
Create query with top 5 and rest
Hi,i want to have a query that gives a list in the following format customer - value of orders #1 - 20.500 #2 - 20.100 #3 - 16.000 #4 - 15.000 #5 - 14.000 Rest - 49.600 how can i a
-
Study Guide book for Java Certified Associate SE 5/6 Exam 1Z0-850
Hello All! I'm a student and Just finished my java course. I planning to take the Java Certified Associate SE 5/6 Exam 1Z0-850 ASAP. My questions: 1) Is there a study guide available for this (thought I could fine OCA SE7 which will be released only