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
Related
I'm working on a project I'm Java with regards to outlook.
Here I'm able to do all the functions like Read a mail, write a mail, reply to a mail etc...
But now we've been thinking of taking it to the next level.
Our plan is as below.
We have an email address like info#myDomain.com, when ever an email is sent to this address, I need to reply them. Here basically customers send an email asking for some data, and we've the data available in our portal, and we just need to send it.
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
And this has to be done automatically when ever there is an email hit to this particular email address.
Couple of questions:
- should my machine be on the whole day to get this thing done.
- is there a way that a Java application can automatically monitor my inbox to see for this case match.
- Also, can I have this running in the bg.
Can someone please point me into the right direction/approach where can I can start working on this task.
Thanks
when ever an email is sent to this address, I need to reply them.
For this you need to monitor your email account fro incoming emails. Here is one of the way to do this
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
Once you receive an email (using above email monitoring approach), you need to call a method that sends the reply with above format
And this has to be done automatically when ever there is an email hit to this particular email address.
Above two steps accomplishes this task.
should my machine be on the whole day to get this thing done
Basically, you will need an application server (like tomcat) where your above java program is deployed. So, yes this server needs to be running and available all the time.
is there a way that a Java application can automatically monitor my inbox to see for this case match
Check point 1
Also, can I have this running in the bg
You can run tomcat as a service in windows (more info). It has many advantages, automatic startup on boot being the one. Similar implementations are also available for other OS.
So, in short, this can be accomplished. It is bit complex but not much difficult. Cheers
I have some automated functionality built into my web app that sends email daily to remind customers of appointments etc. Basically I use an auto scheduler that starts each morning at 7 am, checks the database for customers that need to be emailed, and sends the messages. This is great, but beyond actually sending the email I am completely in the dark.
Can I somehow verify that an email address is actually a real email
and the email has been successfully sent?
What about checking for messages that were delivered to a spam folder
of some sort?
Diving even further...I know there are email services out there that
can provide statistics based on the amount of people who actually
opened the email. How do I check for this sort of thing?
My understanding is (at least for my first question) that I need to check the sender email address for returned or undeliverable emails and deal with them accordingly, but how do I do this programatically with Java? Do I need to implement another automatic daily process that checks an email account for undeliverable emails, handles the error, then removes the message? I assume that because of relay servers etc, an undeliverable error will not be available immediately because of relay servers etc.
I understand this is a slightly vague and loaded question so i'm not necessarily looking for a complete solution, but more or less some advice that will help me get started. I'd rather not use an external service.
Emails are usually fire and forget, so there is no standard way of tracking them down. Having some third party send emails might reduce the chances of your mail getting sent to the spam folder, but sometimes, the mail client seems to learn what emails you delete without even reading and starts trashing the emails immediately.
That being said, you can take a look at this and this previous SO threads. Depending on the content of you mail, there might be some possibilities for you to get some sort of response back.
As for being able to check which email is valid or not, you might consider using some sort of activation mechanism. You basically send them a mail and in it you include a link to which the user will have to navigate to activate some sort of service. If the user activates the link, than you know that they have access to the given email account.
I've done quite a bit of research on this matter and I can't seem to come up with a solid solution to my problem.
I am developing a Java client application that (should) allow users to import their contacts from Mac Address Book by fetching them in a list format and allowing the user to select a subset/all and click a button that would send an "invitation" to these users.
I was able to grab contacts using the Rococoa Java framework but I am uncertain as to how to send email or if it is even possible. I realize there are security concerns with this, but I was able to accomplish this same task on Outlook for PC.
It seems that I may have to call an Applescript from my Java that manually opens Mac Mail Client and sends email using their default mail account setup.
I could be totally off-base here... should I even bother sending mail through the user's default Mail account? I wanted to avoid using a different mail server to avoid spam etc.
Any help would be appreciated, thank you for your time.
Matt
Here's an applescript to use Mail...
set emailSender to "sender#email.com>"
set emailTo to "recipient#email.com"
set theSubject to "The subject of the mail"
set theContent to "message body"
tell application "Mail"
set newMessage to make new outgoing message with properties {sender:emailSender, subject:theSubject, content:theContent, visible:true}
tell newMessage
make new to recipient at end of to recipients with properties {address:emailTo}
send
end tell
end tell
Another option, if you know the smtp information, is to use python. I made a command line program you can use. Find it here. There's example code to use it on the web page.
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.
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.