Regarding exception handling in javamail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   prachi_jain
Posted On:   Wednesday, October 9, 2002 12:48 AM

Hi friends, I need a help, i m using the following code to send a mail. 1) I m not sure whether i m doing proper exception handling or not. 2) I would like to know that, if mail.smtp.host is not working or responding, how can i catch that exception 3) How can smtp.host can send mail back (formatted) when it won't find the mail.(for ex: mailerdemon or so..) I mean to say, if mail id is incorrect. 4) Is there any way to get smtp reply code. Please guide. Thanks and regards. String UID = request.getParameter("user") ; String email = request.getParameter(&qu   More>>

Hi friends,



I need a help, i m using the following code to send a mail.


1) I m not sure whether i m doing proper exception handling or not.


2) I would like to know that, if mail.smtp.host is not working or responding, how can i catch that exception


3) How can smtp.host can send mail back (formatted) when it won't find the mail.(for ex: mailerdemon or so..) I mean to say, if mail id is incorrect.



4) Is there any way to get smtp reply code.







Please guide.


Thanks and regards.



			
String UID = request.getParameter("user") ;
String email = request.getParameter("email") ;
String feedback = request.getParameter("feedback") ;


Properties props = new Properties();
props.put("mail.smtp.host", "IP address");

Session s = Session.getInstance(props,null);

MimeMessage message = new MimeMessage(s);

InternetAddress from = new InternetAddress("some@forum.com");
message.setFrom(from);
InternetAddress to = new InternetAddress("member@forum.com");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Feedback and comments");
StringBuffer MsgBody = new StringBuffer("From: " + UID) ;
MsgBody.append("
");
MsgBody.append("User Mail id is:"+email);
try{

MsgBody.append("
");
MsgBody.append("
");
MsgBody.append("The following is the feedback submitted by the user.");
MsgBody.append("
");
MsgBody.append("
");
MsgBody.append(feedback);
MsgBody.append("
");
MsgBody.append("
");

} catch (Exception Excep){
out.println("IOError" + Excep.getMessage()) ;
}


// Addition for sending the attachment

MimeBodyPart mbpText = new MimeBodyPart();
mbpText.setContent(new String(MsgBody), "text/plain");
// create the second message part
MimeBodyPart mbpAttach = new MimeBodyPart();

// create the Multipart
//and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbpText);
message.setContent(mp);
try {
Transport.send(message);
} catch ( Exception sendEx ) {
out.println(" Send Mail Error " + sendEx ) ;
}
pageContext.include("thanks.jsp");

   <<Less

Re: Regarding exception handling in javamail

Posted By:   Garrett_Smith  
Posted On:   Wednesday, October 16, 2002 08:06 PM

Hey,



Good question. What I like to do is to include a file for errors. In the errors page, I can get the errors.



You can use an ArrayList to store your errors in, and then grab those errors in the included file.



catch (Exception e){
errorList.add("A send mail error occured");
request.setAttribute("errors", errorList);
request.getRequestDispatcher("/errors.jsp").include(request, response);
}
About | Sitemap | Contact