I want to set up a program where all incoming emails into vpopmail of the form
12345678#mydomain.com get forwarded to a java program / daemon that is running
the java program will receive the information about the person sending the email
so it needs to access the standard email and from the account (in the above case 12345678) infer where to send it on. then once it has received a confirmation code from the daemon, delete the email
I'm using a qmail / vpopmail combination on linux (debian), so I'd rather that fire an event to my java daemon than poll the mail accounts, through the java mail extensions.
Any help is greatly appreciated
I'm using a qmail / vpopmail combination on linux (debian), so I'd rather that fire an event to my java daemon than poll the mail accounts, through the java mail extensions.
This sentence implies that you must use IMAP/POP3 access to poll a mail account. If your java app is on the same host as the mail server, it could also poll a Maildir directory directly by looking for new files in the path_to_maildir_folder/new directory.
Maildir on wikipedia
Look into procmail and formail -- see the procmailex manual page and the procmail-lib package on Debian.
Use procmail if it is installed on your system. Put these lines in a .procmailrc file in the home directory of the user who receives the e-mail.
:0
| /path/to/your/program
Or you can instead use a .forward file containing
"|/path/to/your/program"
Procmail has the advantage that it allows you to deal with more complicated filtering if your application ever requires it.
Your program will read the headers and body of the e-mail from stdin.
Related
Good afternoon,
I would like to control a mailbox (it is an internal mailbox, different than gmail, outlook etc..), and I am using POP3 or IMAP to do it.
Everything it is okay, but right now I am using a scheduler to check the e-mail every X minutes. Is there any option like an event or something (or a library/protocol), to launch a function every time an e-mail it is received/created in one folder of the mailbox?
Thanks in advance
This is known as forwarding to a program, or forwarding to a pipe. It was common practice 20-40 years ago. People seem to have forgotten nowadays, but still ask about it.
Your program will receive the email on stdin. If you want to process the email, you can parse your input and do... whatever. If you want to control the inbox, you can forward to both the inbox and the pipe (the aliases/.forward syntax allows that), discard the input from stdin, and and manipulate the inbox. Your program will be started at the right time to do the manipulation you want.
I'm writing an RCON client for an Insurgency (Source engine game) dedicated server. I'm using the RCON protocol defined by Valve that is used in all of the games that use the Source engine. I can successfully send commands to the server, and display the server's response to those commands. However, I have no idea how to read or request the feed displayed by the in-game console (which contains the part I'm primarily interested in: the killfeed). I have looked at querying the server for a possible request to be sent the feed, but there is no such functionality listed.
How would I go about retrieving the console feed from the server?
You cannot request the console feed from the server via RCON.
Two alternative solutions come to mind:
Save the output of the server application
Insurgency (or most source servers for that matter) prints the information you are looking for to stdout. The most elegant solution to save this output would be to start the server via systemd and read it from the syslog via journalctl.
As a more simple solution you can just write it to a file using a pipe:
./start_server.sh > output.log
Or if you still want to see the output as it is printed:
./start_server.sh | tee output.log
Use sourcemod
You can write a sourcemod-plugin, or use an existing one that records and provides those information. The SuperLogs plugin comes to mind, but I haven't used it in a long time. This will be significantly more work.
I have been using the first solution for a long time now. Be aware that Insurgency buffers the output and only writes it once that buffer is full, leading to delays of 20 minutes and upwards. This can be improved by setting sv_logflush 1 in the Insurgency config.
I have postfix email server configure on a linux machine. There is a email account e.g xyz#emailaccount.com is available on this mail server.
What exactly I want to do is Whatever email come to this email id should be converted to .eml file and this .eml file should be stored on a perticular location on hard disk.
I want to automate this above process using java program. I thought that my java progam will run after certain interval of time using schedular and check for any new email. As soon as he found any new email he will
convert that email to .eml file and store this file on a perticular location. The mail coming to this email id mostly dont have any attachment to them. But still I want my program robust so that if unfortunately if some
email comes with an attachment in that case the java program should not stop working.
Following are my questions that I want to ask to expert.
Is what am I expecting in above case is possible? and Whether is it possible in java?
As I checked on mail server the mail files for above email id have very long name and I dont found any extension to them. So How do I read mail in these files and convert them in .eml format using java.
If you know any tutorial related to above task or any reference link of code then please let me know about it.
I check on web and found that java have javamail api. Is this pacakage is helpfull for me to do above task or do I have to use any other api for java? If you know anything it it please let me know.
Please help me in above task friends.
Thanks in advance
Yes, it's possible.
The simplest approach is to run an IMAP mail server to allow you to read the messages using JavaMail. There are several IMAP mail servers available for Linux.
See the documentation on the JavaMail project page, especially the JavaMail FAQ.
Use JavaMail.
I have a constantly-running Java program that needs to send an email whenever it encounters a problem. However it is possible that the mail server it uses could be down at the time it tries to send the email.
What is the best way to ensure that the email will be delivered when the mail server comes back up?
Queue up the requests. Have a separate thread which merely waits for something to enter the queue, then tries to email it. If it fails, it waits a few hours and tries again. Once it sends a message, it goes back to the queue to get the next message.
Put the email object into a stack or list when it fails to send, when the email server comes back up, pop each email out until it is empty.
You may want to save the email in a file, perhaps an xml file, so that should the application crash you won't lose this information.
This file is loaded when the application starts, and it keeps everything in memory, so that while there are pending emails then it keeps checking every 5 minutes or so, then, as it sends each email it will resave the xml file, so that should it crash after sending 3 emails out of 10 it won't resend those three when it starts up.
But, how you handle that is really going to depend on the specification for how to handle error conditions.
If you go from "forward everything to this SMTP server which is always there" to a situation where you need to handle all kinds of conditions normally handled by a full SMTP-server like retry later, retransmit if connection closed, use MX-hosts in their stated order and similar, you may want to consider simply having a SMTP-server inside your client (but one that does not accept incoming connections) since this moves all the dirty logic away from your applications.
I believe that the James email server - http://james.apache.org/ - is easily embeddable, but I have not actually tried.
The suggestion of using James is a good one but I've had some issues in the past of James being a bit flaky and needing to be restarted.
You could use something like Quartz to have a scheduler check for messages that need to be sent. If the message can't be sent (eg. smtp server isn't available), then that message is rescheduled to be sent at a later time. You could either have a task per message or have a persistent task that checks for messages and available mail server then sends the messages. The persistent task would give you email batching.
If you are in a Unix/Linux world, then consider the alternative of sending your alerts using syslog, and dealing with the generation of emails on that side. For example, nsyslogd has a module called ommail for generating emails natively.
IIRC, there are adapters for log4j and the like that can bridge between the Java and syslog worlds with a minimum of (zero ?) coding.
Apache James - http://james.apache.org/ will let you run your own mailserver as a proxy, not only that but is written in 100% java, so you can figure out what its doing,
and as an extra bonus James uses databases to queue the mail, so you can even inject mail directly into the queues by inserting into a database, then leave whole business of sending the mail up to James.
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.