File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Create e-mail via servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Create e-mail via servlet" Watch "Create e-mail via servlet" New topic
Author

Create e-mail via servlet

Alexander D�ubler
Greenhorn

Joined: Feb 15, 2006
Posts: 11
Hi,

I'm currently implementing a web application which creates certain documents (PDF and DOC) using a servlet and displays them in a browser.

Now mail functionality is to be added as follows: after the document has been created, it is sent to a particular address as an e-mail attachment.

What I want to achieve is that the servlet creates the mail as a mime message in a way that the browser automatedly opens Outlook after it has received the message from the servlet. Unfortunately, for security purposes it is impossible to send the mail directly from the servlet-containes, but the mail must be returned to the client first.

Anyone got any idea???

Thanks, Alex
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
I would say JavaMail would do all the jobs of managing e-mail; see:

http://java.sun.com/products/javamail

But I'm not quite sure about "the browser automatedly [automatically] opens Outlook after it has received the message from the servlet". Firstly, what's to say that the client uses Outlook at all? Even if they don't (and what you meant to say was "opens the mail client" rather than "opens Outlook"), sending e-mail via SMTP and sending HTTP messages are two completely different things - they don't really overlap. As a result, you can't send an e-mail from a servlet via HTTP to the client's browser. You can however send an e-mail via SMTP (a separate process) to the client, and you can achieve this using some servlet (or any Java) code - but that's a different thing altogether.

If you need clarification, please ask away...
[ March 17, 2006: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Alexander D�ubler
Greenhorn

Joined: Feb 15, 2006
Posts: 11
First of all, thanks for the quick answer!

Yes, you're right, I meant 'open the default mail-client', of course... But on the other hand I'm quite sure that 99.99% of our customers are currently using Outlook as the default client. Well, be that as it may...

Could you please tell me more about sending the mail via SMTP to the browser? Is it thereby possible to open the default mail client?

Or is there any possibility to use JavaMail to send the mail directly from the server (instead of the client) to the receiver without getting into trouble with any security restrictions?


The main purpose of the mail functionality is as follows: the user that is currently logged on to the system creates a document, which is to be sent to the receiver of the document via e-mail. however, the document is not being created on the client machine but on the server. If the e-mail could somehow be sent to the client and automatedly opened in the default e-mail client then the user just needed to click on the send button and everything was fine. However, if the mail is being sent directly from the server authentication was needed, but there shouldn't be any commitment to the user to enter any password after logging on to the OS)...

I hope that made it a bit more clearer what our objectives are...


Thanks, Alex
[ March 17, 2006: Message edited by: Alexander D�ubler ]
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Could you please tell me more about sending the mail via SMTP to the browser? Is it thereby possible to open the default mail client?
E-mail isn't sent to the browser - it is sent to the user's e-mail inbox; they can then use a mail client to retrieve the messages from their inbox. The only way I know to get the mail client to open from the browser is when you use a hyperlink to open a new e-mail (using <a href="mailto:..."> , but that's a sending not receiving operation for the client.

Or is there any possibility to use JavaMail to send the mail directly from the server (instead of the client) to the receiver without getting into trouble with any security restrictions?


Absolutely - the point of JavaMail is to act as an interface for sending and receiving general e-mails. It wouldn't cause the mail client to open by default, but you could use an HTML message to alert the user that an e-mail has been sent to them, thereby prompting them to check for new mail. In order to send e-mails from JavaMail, all you need is an SMTP server (and the necessary permissions to use or relay from it) - you don't even have to be using J2EE to do this (there are many Java mail clients out there using JavaMail to send/receive e-mail from client machines)!

Depending on how confident you are with Java as a whole, and how much of the technical details of e-mail you know about, I would either recommend looking at the API and deducing things from that, or alternatively finding a tutorial on the Web - trying searching Google for "JavaMail tutorial" or similar. You might also want to check/ask in the Other Java APIs forum, since that covers JavaMail.

Good luck!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
The mail server you use for your personal mail may not be happy with handling mail from your servlet since it may look like spam from a mail zombie. The Apache "James" mail server in Java works for me.
Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create e-mail via servlet
 
Similar Threads
Pretty confused with these 2 hosting sites
Throw exception if mail server doesn�t respond
activate user account through email
sending email
JavaMail question