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.
Related
I have an alpha staged program with many bugs, and I would like to let people send their logs on a server (mail, git, etc...) so i can look them up and fix them. I have searched allot on this topic and I haven't found a way to do it without downloading a git full of logs, or needing an authentication for a mail or a dedicated server.
Is there a way to make my Java program send automatically its error log on a server when it crashes, without needing costly hardware or authentification? (i have a 0$ budget).
A free Loggly account sounds perfect for your needs.
You could use the javamail library to send emails to an account where you want to get the errorlogs. This wouldn't cost anything. And is very fast to implement/integrate in your project.
I would suggest to create a new gmail account which will send the emails to your account, where you want to recieve and debug it.
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
I'm writing a program, that sends email messages and want to know when the receiver receives the email message I've sent to him. How can I do this using JavaMail API?
If I use SMTPMessage, how exactly to deal with the result after I've set the notify options?
SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);
There is no standard way of doing this that's accepted and honored across the board. I see that you have some options, though:
Add a header "Return-Receipt-To" with your e-mail address in the value. If the recipient of the e-mail has a client which honors this header, then a return receipt will be sent to you when the e-mail is opened. This is not reliable, mind you, as the user can always decide not to send the receipt, even if he has a client that supports it.
Add an image into your e-mail that loads from your server and put a parameter on the image that includes the user's e-mail address. When the e-mail loads, the image will load from your server. Write a script that collects the e-mail parameter and then delivers a blank image. This is also not reliable, however, as many mail clients prompt users if they wish to download images and they can always choose not to. Also, some (mostly older) e-mail clients do not support images.
Perhaps the most reliable way is not to include the message in your e-mail at all. Include only a link to a website where the message can be read, and include their e-mail address or a unique code in the link. This way, you know exactly who read the message. Of course, this has the downside that people aren't actually getting the message in their inbox, and they also may choose not to go to the website to read it.
Ultimately, I think you're going to have to come up with a creative solution to solve this problem, unless you're happy getting spotty results.
Ok, this is an old discussion, but:
I've found a simple and working solution here (link in spanish).
You just need to add one more field to the header of the message. To achieve this you must use method addHeader of Part class, implemented by Message class. This method receives 2 parameters, type and value of header.
To get confirmation you must add this header:
Disposition-Notification-To
And the value is the mail where we want to send the confirmation answer:
message.addHeader("Disposition-Notification-To","mail#example.com");
ATTENTION: be aware that, nowadays, a lot of mail servers like gmail are discarding this requests, so this will not have effect, but, if you are sure (like me) receiver server allows this, will work like a charm.
please see my answer here (when this questioned was asked about ruby on rails). Tis basically the same answer.
Email open notification - ruby on rails
There is another approach to finding out whether an email has been received or not, it's getting undelivered emails. I've seen a rather good Java implementation here.
They used javax.mail (for mail processing) and guava (for processing strings and collections).
Just add a dummy image with display set to none in your message.And set the src attribute of this image to the url you want to call
You can use SMTP message and request for a delivery status (I don't know if it's coming when the provider receive the mail or if it's when the user open the mail).
JavaMail don't support directly these feature directly and you have to read the RFC 3464.
I also find this thread with examples but didn't try it javamail
You can also look at websina
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
in my webapplications whihc runs on tomcat on widows i want to send email to many different people
for example whenever a new tutials is uploaded on my site an email shold go to all the registed user on my site.
simlarly whenever some other event occors i need to send the email to some selected users whose emailid are picked up from database.
I want a jar which can be used to send such messages.
I wil pass a array of receipienst to it.
are there some free jars available for this ??
jars shold me able to queue the msgs and send to the recipients
let me explain in detail
You need JavaMail
Check out commons email
The "queue" ability usually requires a SMTP server which traditionally is provided by your Internet Service Provider. You then use e.g. JavaMail to generate all those mails you need to send and forward them to the SMTP-server and let it handle all the details.
If you really, really need to run your own SMTP-server, I believe James can do it (http://james.apache.org/) but I would recommend the ISP approach.