aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending HTML format mail thru JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending HTML format mail thru JSP " Watch "Sending HTML format mail thru JSP " New topic
Author

Sending HTML format mail thru JSP

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Dear Ranchers,
I'm doing a dynamic website using JSP and MySQL. I want to send html format mail using JSP. How can it be possible. Please send me some links or tutorials that i can get this knowledge.

Thanks in advance

regards

Aravind Prasad
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

What is "html format mail" ?

Do you want the body of your mail to be of html type ? Have a look at the java mail API and the SMTP protocol.

Here is a tutorial

http://java.sun.com/developer/onlineTraining/JavaMail/contents.html


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Thankyou John Meyers,
I have looked into the JavaMail tutorial and I am not convinced with the output. I'm still getting errors while sending. I want the code for sending the mail. For that i've used this code and it is working in my localhost system, but when i uploaded to the remote server, it is not working. Can you please tell me the reason?

Here is the code


regards

Aravind Prasad
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
If it is working when run on your local system but not on a server, the problem could be security at the mail server. Typically mail servers only accept outgoing mail from certain senders and your JSP server is not cleared to send mail through the system you are trying to use.

Bill
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Thanks for the reply.
Now i'm trying to run a simple java mail application from JavaMail API tutuorial and it is showing me errors

The code is here



and the error i'm getting is here



I've added all the jar file in the classpath. Please assist me how can i fix this problem.

Thanks in advance

regards

Aravind Prasad
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

You cant use "session" when its already an implicit object.

MimeMessage(HttpSession) does not exist. MimeMessage(Session) does
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

This has not a thing to do with JSP. Moved to Other Java APIs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
When sending an message with html use the set content method of the MimeMessage class. i.e mimeMessage.setContent(htmlString,"text/html");

You may want to check the implementation of transport.send and smtptransport. I think it blocks until the first server in the delivery chain accepts the message for each recipient (cant remember exactly). If this is the case, sending the mail asynchronously will provide a better user experience especially in cases where a MX record points to a dead or slow server.


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Sending HTML format mail thru JSP