I am developing a Java app that reads all the emails from GMAIL and save them run time on objects of self made Class that holds some of the attributes of the email. Now I want to delete an email object and when I do that I want it to be removed from the internet as well. In order to do so I will need some information to query the GMAIL account to delete that particular email I am referring to. Is there a possible way to do that? Maybe by saving the header and then searching for that? I couldn't find a good way to do it.
I assume you are accessing GMAIL with IMAP. Then you could store the Message, call Message.setFlag(Flag.DELETED) then expunge the Folder, or search the Folder yourself. Or maybe you can search the Google Gmail api and find a better way. For example you can use the unique message ID
UPDATE this is a google project that can help you: java-gmail-imap. There is also a companion project for OAuth authentication (needed for run the sample)
I'd recommend you to take a look on James.
The Apache James Project delivers a rich set of open source modules and libraries, written in Java, related to Internet mail communication which build into an advanced enterprise mail server.
It depends on the time span between when you access the message and when you want to delete it. If it's short, and the folder is still open, you can just set the DELETED flag and close the folder to expunge the message.
But I'm assuming that you need to locate the message some time later. In that case, you should learn about IMAP UIDs. See the UIDFolder interface in JavaMail and the IMAP spec for details. In essence, you need to keep track of the folder's UIDVALIDITY value and the message's UID value. When you come back to the folder, you can make sure it's the same folder by checking the UIDVALIDITY value and then look up the message based on its UID.
Related
I've made a simple mailing app that takes in email credentials and uses it to send emails of certain kinds to selected addresses. Problem is, I've had to input the credentials right into the code, so anyone who uses dex2jar can get the source code and get the email used for forwarding and easily make the app obsolete.
I imagine I'm not the only one facing this issue, so what are some ways to make my code secure?
No matter how good of a technique you use to hide the credentials, if it's in the code then it can always be found.
Instead of hard coding them in, you could perhaps let the user specify them when he starts the app? If that can't be avoided you could instead have a remote service that will do the sending and forward your request to that.
You can not both connect to an e-mail account and keep those same users out of said e-mail account. Consider using a hosted server as part of the project to securely connect to the e-mail account from the server level and process these e-mails remotely.
I'm developing a chat application using Tigase server in the background for providing the XMPP communication. Besides that I'm using smack/asmack as a library in my application.
With every message send between the users, for the sake of the functionalities I want to implement I'm including package extensions via smack's Presence.setProperty() method,which are correctly send if both of the users are online. When one of the users is offline the Tigase server saves that message and then delivers it when the user becomes online again. The thing is that Tigase don't save the message including the packet extensions, so when the user is online again it receives only "parts" of the message send.
I found the Tigase source and found the place in the OfflineMessages class part of the xmpp.impl package, where I need to insert a line of code in order for msgoffline plugin to save the offline messages using extensions.
What is the easiest way to override the OfflineMessages class in Tigase jar file, without building the whole source code of the project?
I'm using Tigase-5.1.5-b3164 version on ubuntu server and Eclipse as IDE.
I do not know Smack library, hence I do not know what Presence.setProperty() method does. But if it does something to a presence packet (adding an extra payload to the presence status) then this will not be saved to offline message storage because.... presences are not stored in offline message storage.
If you want to modify OfflineMessages to make it store more different data than it stores now (like a specific presence packets) then there is a method: savePacketForOffLineUser with a big IF at the beginning. This is where the decision is made on what to store in an offline storage.
But, please be careful not to store ALL presences, it will kill your service and your database.
The best way to add your own plugins is to make a copy of the existing Tigase plugin (OfflineMessgae), modify it to your preferences, change a name of the plugin and ID of the plugin. Then you just put a jar with your code into Tigase jars directory and modify configuration to load your plying instead of the default one. This way you do not have to recompile Tigase sources and will be also easier for you to update to a new version.
I want to extract "To" and "Subject" from email clent which is already configured in android emulator.
so, is any api to extract or to get all email attributes?
Thanx in advance,
No, sorry.
Bear in mind that there is no single email client in Android. The Android open source project has one, but device manufacturers can (and do) replace it. Plus there is Gmail and other third-party mail clients (e.g., K9). Hence, there is no single email client "which is already configured in android". And the open source one is not part of the SDK, so there is nothing in the API for accessing it.
I have written a nice program in Java that connects to a gmail account and download atachments sent to it. Once an attachment has been downloaded, it is marked as read and is not downloaded ever again. This program will have to run in multiple instances with each program downloading unique attachments so that a single attachment is never downloaded twice. The problem is that at the moment if the attachment is of a decent size, one program is still downloading it, when another instance connects and also starts to download the attachment before it has been marked as read.
I have tried checking and setting various flags and checking whether the folder is open, nothing seems to work. Any solutions?
Update: Thank you for the quick answers, sadly IMAP is not an option due to other reasons.
Consider using IMAP instead - it is designed for client-server interaction.
From RFC1939 (Post Office Protocol - Version 3):
POP3 is not intended to provide
extensive manipulation operations of
mail on the server; normally, mail is
downloaded and then deleted. A more advanced (and complex) protocol, IMAP4, is discussed in RFC1730.
I don't think POP3 is made for multiple simultaneous access.
Ask yourself this: do i really need multiple processes accessing the same mailbox?
If you do, you'll have to find a way to have these processes communicate to each other.
Use a common database or server process to coordinate actions.
IMAP does have more options, but i'm not sure if you can "lock" a single mail to mark it as being processed.
As the others have mentioned, POP3 isn't really intended for this kind of scenario.
If you absolutely have to use POP3, I'd suggest downloading all the e-mail to an intermediate server which sorts the messages and makes them available for each of the other clients.
It sounds like you're just trying to distribute the processing of the e-mails. If that's the case, you can just have each client connect to your intermediate server to retrieve the next available message.
I'm not sure what your constraints are, but you may even want to consider receiving the attachments some other way besides e-mail. If people are uploading files, you could set up a web form that automatically sends each file to the next available instance of your application for processing.
If you need to stay with a POP3 connection, you could keep a local database of previously downloaded message ids. Then new instances could check against that before downloading again. The best solution is just to use IMAP, though, as IMAP is able to set the read/unread flags before downloading.
You could mark the mail as read before starting the download, and then start downloading it.
Just got a request from my boss for an application I'm working on. Basically we're getting an email address setup for an external client to submit excel files to.
What I need is a way to automatically pick up any email sent to this address, so I can take the attachment, process it and save it to a folder.
Any information of even where to start would be helpful.\
Note: We're using a lotus notes server to do this, but a generic way would be more helpful (If possible).
Email -> mailserver ->[something] -> file-on-disk.
File on disk is pretty easy to parse, use JavaMail.
The [something] could be:
listener for smtp connections (overkill)!
Pop3/imap client
Maildir/Mailbox
Edit: since I first wrote this answer, Wiser has moved and now claims to only be a unit testing tool, so take the answer below with a pinch of salt...
Svrist's answer is good, but if you want to avoid his middle step (the mailserver that writes the mail to disk for later pickup by the Java system) you can use Wiser.
Wiser lets you start an in-Java mailserver:
Wiser wiser = new Wiser();
wiser.setPort(2500);
wiser.start();
Then you can just poll it periodically for mail:
for (WiserMessage message : wiser.getMessages())
{
String envelopeSender = message.getEnvelopeSender();
String envelopeReceiver = message.getEnvelopeReceiver();
MimeMessage mess = message.getMimeMessage();
// mail processing goes here
}
Use a mail in database (your Domino administrator can set that up for you but it's in the help file as well).
In that database, you can create an agent that runs periodically to process all new documents. That agent will use the EmbeddedObjects property of the NotesRichTextItem class and the ExtractFile method of the NotesEmbeddedObject class to get a handle on the file attachment and extract it to the location you specify.
For example, this script goes through all the file attachments, object links, and embedded objects in the Body item of a document. Each time it finds a file attachment, it detaches the file to the SAMPLES directory on the C drive and removes the attachment from the document
Dim doc As NotesDocument
Dim rtitem As Variant
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
Call o.ExtractFile( "c:\samples\" & o.Source )
Call o.Remove
Call doc.Save( False, True )
End If
End Forall
End If
I've done quite a bit lately with Java agents on Domino servers. The Domino 8.5 server supports Java 6 and its embedded so it won't take someone with a bit of Domino development experience long to put together an agent that runs when new mail arrives. In LotusScript its even easier but that needs more specialised skills which you'd probably need to get a contractor in to provide.
The limitation your likely to encounter concerns the extracted file, you can easily place it on the Domino server's file structure but you may be limited by the OS security from placing it on a different server.
Lotus Notes/Domino stores mail in a Notes database. There are APIs available for getting documents (emails), reading field values (From, Subject), and detaching files.
APIs include
-LotusScript (VB variant, available within the Notes database)
-Java (from within or external to the database)
-C API (external)
-Same API available through COM server
You can create a "scheduled agent" within the database (using LotusScript or Java) that can locate documents created since it last ran, locate the attachments, and extract them. The agent will need to be signed with an ID that has the appropriate permissions on the server, including those required to write to the file system and initiate any other processes.
External to the database, you can use any API except LotusScript to log-in to the server/mail database, and follow a similar process, e.g. extracting the files locally on a client or separate server. C API and COM require a notes client install, but Java applications can be set up to run via CORBA/DIIOP without a full install.
Consult the Domino Designer help (or IBM's website for C API) for more information.
As to a "generic way" to do this, if you are accessing data in Notes and needing to extract attachments, I believe these APIs are your best option. If you envision porting the application to another mail system, consider decoupling the API routines via an "interface" so you only need to add a new implementation of that interface to support a new mail system.
You can access Notes Documents relatively easily using DIIOP, would be a lot easier than going down the C Api road...
Try POP3Client in the Net Commons package; it'll let your Java program check for new mail for a particular account at whatever interval you want (every few minutes? hourly?), and get/delete messages as desired.
SMTP/POP3 can be enabled on the Domino server. Worked with this before and gotten Squirrel Mail running with it. SMTP is a bit resource intensive, but well worth the effort because then you don't have to descend into LotusLand to get things working. Just write a small Java CLI program that will check a specific email box (POP3 or SMTP), and parse through the messages, pulling the attachments and placing them where needed.
Plenty of documentation and examples here:
http://java.sun.com/products/javamail/
The techniques that you develop taking this approach will be more widely applicable in your future career than anything Lotus/Domino specific.
No matter what you do, you'll need an understanding of the Lotus Notes data structures. The good news is that a fully automated solution can be built in Notes very easily.
Your best bet is to have it built within Notes, and it can be set up to run automatically whenever new mail is received. Gary's answer is dead on, but without any experience, it would probably be hard to figure out how to implement it yourself. On the other hand, it really shouldn't take any competent Notes programmer more than an hour or two to set it up.