Do you know any framework in Java for reliably sending a huge amount of emails with the following features:
Send and receive emails
Concurrently process emails from a queue to maximize the throughput
Keep track of emails that could not be delivered
I know that writing my own is not very hard, but I was wondering whether there is already something sophisticated that I can reuse.
UPDATE: The use case for my question is not sending newsletters or spam. It's emergency mass notification, e.g. sending 50,000 emails within 5 minutes. I also do not want to implement my own mail server, I want to use existing mail server(s) with the JavaMail API. But the JavaMail API doesn't provide any facilities for queing and concurrently sending emails and keeping track of emails that could not be sent.
You use the Java Mail API to construct the actual messages you want to send, and let JavaMail use a production quality mail server to do the actual delivery.
An easy configuration to get up and running is postfix under Ubuntu Server.
Please, please, please do not send out unsolicited spam.
Send and receive emails? Perhaps you are looking for mailing list manager in Java? Take a look at Subetha which is successfully used in several production sites (and written in Java). http://code.google.com/p/subetha/
They have a sub module, called Subethasmtp, which you can use as a smtp server (in Java).
Try the Java Mail API. But for really bulk mailing you probably want to talk directly to SMTP.
You can use "JavaMail" or "GreenMail" for sending and receiving email
Related
From a search, I can find a lot of similar questions to this but all of them seem as far as I can tell to have either been misunderstood or to not be quite the same as this question.
Presumably (maybe not but it seem unlikely) an email process/server knows which emails it holds a record of because they "arrived" and which it holds a record of because someone used SMTP or similar to tell the server to "send" an email out.
If a POP3 client retrieves lots of emails from the server and (we know from observation that) some of those emails are emails that the server was told to send out and some are emails it received, then is the pop3 server contravening the protocol because it provided for download, emails which were conceptually NOT in the "Inbox" or is it at liberty to send what ever it wants since POP3 has NO concept of folders and emails are emails.
Either way, is there an easy and robust way for the client to distinguish between these emails? Or is checking the from field against the account the best on offer? I believe pop3 messages support flags, some POP3 apis do, but perhaps servers are not obliged to make any guarantees, plus I don't see a very clear description of their meaning, so I don't if they can be consisently used to distinguish.
For implementation my preference is Java and com.sun.mail.pop3
I realize there is IMAP, but at this stage I'd like if possible to make a very small change to POP3 client implementation and look at switching to IMAP another time.
Thank you.
POP3 is a protocol to get the messages of your inbox. To send messages you use SMTP protocol.
In my understanding you contact the server using SMTP and deliver a message to the server. The server then delivers this mail to the corresponding target mail server and stores the message in that inbox.
On the other side you contact your own inbox using POP3 to receive the message that are stored in your inbox.
Thus there never should be any conflict between ingoing and outgoing emails as these are two different things and the servers supplying pop3 and smtp for your mailbox can be two total different servers on total different locations. Thus, within one mail server inbox and outbox should be two different storage locations.
"Conclusively distinguishing" depends on how/why the messages are being seen in POP3. A best effort type solution, though, would involve substring scanning the From field looking for what was provided in the USER command. If a token based authentication mechanism is being used, then you'll need to get an email identifier from whomever issued the token and look for that in From header.
As background, a basic concept in POP3 is called the "maildrop". Most people equate that to "Inbox" in IMAP terms, but it's not necessarily the same. For example, a message filtered at deposit time into a custom folder might show up in POP3's maildrop even though it doesn't show in Inbox via IMAP or Webmail. What goes into the maildrop and is therefore seen in POP3 can vary from implementation to implementation.
If a user only has POP3/SMTP and Webmail as their choices, they'll sometimes BCC themselves on sending to make sure a copy exists somewhere on the server so that they can access it via Webmail if needed. That's because very few SMTP implementations automatically save the message to the user's mailbox, and POP3 has no mechanism for saving the message anywhere but local to the user-agent. For those SMTP servers that do automatically save sent mail in the mailbox, they might just put it in the maildrop when it comes to POP3 servers.
I'd like to write a program, probably a servlet or something to run on the a google app engine that I can send an email to. So not a program to send email, but one that can receieve it and parse it.
My question is, what code or API are out there that can receive an email?
Basically on your google app engine you can use an inbound mail service.
Please see this documentation for more information.
http://code.google.com/appengine/docs/java/mail/overview.html#Receiving_Mail_in_Java
You cant send an email to a program, you send an email to a server, so what you are looking for is a way to access an email server via your program. Unfortunately there is no single solution here, you need to configure your program for every different email account/server you want to access. (If you have ever set up an account in outlook or something like it you will get the idea)
For example here is a link to the gmail api, you could use this to access gmail accounts
http://code.google.com/apis/gmail/
You need to have a mailbox to send message there and you could read messages with the code like this: http://www.java2s.com/Code/Java/Network-Protocol/GetEmailMessageExample.htm
This can be done with a built in Java library.
javax.mail
Check out this link. It should be able to help you get started.
This won't work for every mail server, but depending on your setup it might help.
To send an email to a Java program, that program must be running. Generally that means a server style (aka service) receiver is favored.
For the email to be received, the Java service must understand an email protocol. There are a number of protocols, but SMTP is the standard for receiving email. Once you have a service that understands SMTP protocol for receiving email, you have written a mail server.
Note that most people don't care to write a mail server, as a mail client needs to connect to the server and pull the email to make it readable. Keep this in mind when designing the solution to your problem.
I have a project with a use case where users should be able to send private messages to other users but this should be integrated with their e-mail box. They should be able to send either private messages or e-mail messages from the same screen.
My thought is to use some kind of open-source e-mail server which will dump the e-mails into MongoDB and then have my Java API pull them out and display them on the interface. And when a user sends an e-mail it is passed by the API to the e-mail server.
Is this a reasonable approach?
If you want your own server (not unreasonable in many cases), check out Apache James - an open-source Java mail server with a plug-in capability. Obviously (!) you can use JavaMail to talk to this, pull messages back etc.
Doesn't Gmail do all of this already? If you want email with chat integration,* that's the first solution that comes to mind. Why reinvent the wheel?
*and about a bajillion other awesome features
I'd like to ask few questions about handling POP3 protocol with JavaMail (I'm building small web mail client):
How do I know which mail is new? Mail server doesn't provide this info explicitely. I have to iterate thru all mails and check with my database, which are new
What if someone sends a really big attachment? Is there way how not to download it and limit it to certain size? Like with MimePart?
POP offers only two reliable ways to keep track of which messages you've already downloaded. First is to delete them after downloading, which you evidently don't want to do. And second is to track UIDLs in your local database.
There is no way to download a subset of message parts via POP, as POP doesn't include a message structure model. You can fetch the first N lines from a message if the POP server supports the TOP command, but that probably isn't what you want.
It sounds like you want IMAP, not POP.
I have java web application to which I'd like to add emailing capabilities, however, I'm unsure what is needed to accomplish this. Specifically I want my app to be able to:
Send emails confirming sign-up
Allow users to send emails to one another, using my app's domain i.e. dan#my-app.com
From my research it seems I'll need a mail transfer agent (MTA) like Postfix and possibly a IMAP server like Courier; but I don't understand the need for the IMAP server.
Thanks.
You need code inside your web app to create and dispatch the email into the SMTP-world. Usually JavaMail is used for this, and you can either enclose it in your web application or (preferred) have the web container provide a correctly configured instance through JNDI. This is vendor specific.
If you do not have a SMTP-server for JavaMail to connect to (frequently this is Exchange for Windows shops), you can either get one running (ask your IT administrator) or use Google Mail or Hotmail or others if it is ok for your web application to send mail through them. It is a bit tricky to use GMail as a SMTP-server, but when set up correctly works very well.
You will need the SMTP-server, as it handles all the boring details regarding MX records and resending if the SMTP-server does graylisting, etc. etc.
Oh, and IMAP is for getting delivered mail, not sending mail. You don't need it.
If it's a Java web app, then the server part is a servlet. Given an email message sent from a client form, your server needs to send that text off as an email.
There's code in the Java EE stack to do this, or you can specifically download JavaMail. This will allow your programs to act as mail clients.
Your MTA receives messages from your servlet and sends them to the users. So far so good.
But you also need a postbox, i.e. the equivalent of a mail in-box for your users. Postfix, QMail and others offer a basic "flat" mailbox model, where mail is simply stored until the client picks it up, and then (usually) deleted. Access is via POP3. IMAP offers a lot more organizational capability, i.e. the ability to specify hierarchies of nested mailboxes, to transfer mails between them and so on. You probably won't want to create a GUI front end to all that complexity, so I'd guess you don't really need an IMAP server. You do, however, want a relatively simple POP3 server to allow your servlet to access the mailboxes via TCP/IP. This is usually part of the "standard" email server packages.
To have your own domain known to the world, you need access to the MX records of your DNS service, i.e. you have to set up one or two of your hosts, on an Internet-facing address, to be your post office.
Finally, if you want to save yourself a lot of trouble, be very careful in configuring your MTA (SMTP server) such that there is no chance for it being used as an open relay. i.e. it should not be possible for your users to send mail to the outside world in general (or hackers will find a way to abuse your Web interface to do this), and mail from the Internet should not reach your users. Most importantly, there should be no way for mail from the Internet to be forwarded to someplace else in the Internet. Find an open relay testing service (they're free) on the 'net and get one to run a test on your configuration once you think you're done.
EDIT:
Looking at Thorbjorn's answer, I realized you probably don't want your users receiving their mail through your app; they probably already have email providers and accounts of their own. In that case, you don't need to worry about inbox capability or a POP3 server. You could consider offering full email services at your domain but that's a very thankless job and if you have any choice, leave that dirty work to GMail, Yahoo, Hotmail and their ilk. Whatever service you provide will never please your customers enough, and you'll be fighting spam and other crime every day.
For starters your server has to have mailing abilities. In linux land sendmail is usually what this will be.
Additionally, check out javaMail.
http://www.oracle.com/technetwork/java/index-jsp-139225.html