English 中文(简体)
How to track an email in Java?
原标题:
  • 时间:2009-11-17 08:42:25
  •  标签:
  • java
  • email

How I can track an email?

I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

最佳回答

This is not a Java specific issue.

  1. You can create an HTML email, and embed an invisible gif which will report back to your server. Some software like Outlook and some web mail programs will block this for untrusted emails.
  2. You can request a return receipt. Many mail programs ignore this entirely, and the ones which don t usually ask the user if they want to send it.

Example:

email.AddHeaderField("Disposition-Notification-To","<g.revolution@stackoverflow.com>")
问题回答

There is no way to ensure that you always get the delivery or open-message notification.

Mailservers may accept the mail and drop it afterwards. users may read the mail but dismiss the notification.

"Webbugs" (aka images in the html source of the mail that include a special token that allows the mail to be recognized) don t work in most email programs.

As a matter of fact it s very unlikely that you can see that someone got the message.

What you could do is to keep the message on your server and only send a link. If the user clicks that you can be pretty sure that he got the message. But thankfully many users would not click on such links because it s used in fraud and spam.

I suppose you re sending it through SMTP. Whenever your mail is sent to your SMTP server, your java program has no control of it:

1) If you want to know if your mail has been delivered, you should contact your SMTP server somehow (if the SMTP server is outside your control then forget that) and see if your mail has been sent.

2) You can t know if a mail has been opened by its receiver. The maximum you can do is set a flag that the mail requires acknowledgement, but that depends if the user explicitly wants to send that acknowledgment. Other possibility is set some link to your site within the mail that should be clicked to see the content. You will be able to track if the user clicked that link.

what you can do is - you have to embed an invisible image in the body in which the src will call the page in server and log that event, you can only do it in HTML encoding.

example -

<img src="ImageServer.aspx?imageID=track.jpg& custID=134ghxx34343ai& campID=32434"/>

and then in ImageServer.aspx there will a handling code which will log that event or save it to database.

example -

private void Page_Load(object sender, System.EventArgs e)
{
    // content type should be resolved programmatically
    Response.ContentType = "image/jpeg";
    if (!IsPostBack) Track();
    Response.WriteFile(GetImageFileByID());
}

In case you send HTML email, you could add a 1x1 pixel image with some tracking parameters, that calls back to your webserver. It s not 100% reliable since some email clients (and users) block images in emails.

You can add something like

<span style="display:none">Tracking no: ${TRACK_NO}</span>
to the body of the email. This should always be in the response unless the email client strips it out.




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签