Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-02-2008, 12:34 PM
Member
 
Join Date: Apr 2008
Location: villupuram
Posts: 20
sundarjothi is on a distinguished road
Send a message via AIM to sundarjothi
Java mail problem Urgent
hi everyone ,

java mail program successfully run on local tomcat server.
But this java mail program not run on internet tomcat server.
i dont know what is reason.
but i did not get any exception from server.
please help.

This is my code
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//Host name, to address, from address
String to = "career@company.com";
String host = "companyhost";
String from = "company@company.com";

//Attachments file,subject, body information
//Getting from html file with help ajax

String name=request.getParameter("name");
String qualification =request.getParameter("qualification");
String percentage=request.getParameter("percentage");
String fromEmail =request.getParameter("fromEmail");
String phoneno=request.getParameter("phoneno");
String keySkills=request.getParameter("keySkills");
String yearExp=request.getParameter("yearExp");
String filename=request.getParameter("filename");
boolean flag=false;

//System.out.println(filename);
//String filename="c:/Help.doc";

//boolean debug = Boolean.valueOf(filename).booleanValue();
String msgText1 = "Name :"+ name + "\nPercentage :" + percentage + "\nFrom Email :" + fromEmail + "\nPhone Number :" + phoneno + "\nKey Skills :" + keySkills + "\nExperience :" + yearExp +" years";
String subject = name+" / "+qualification;

// create some properties and get the default Session
//Properties props = System.getProperties();
//props.put("mail.smtp.host", host);
//props.put("mail.smtp.port", port);
//props.put("mail.debug", "true");


//Create some properties and get the default session
Authenticator authenticator = new Authenticator();
Properties properties = new Properties();
properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserN ame());
properties.setProperty("mail.smtp.auth", "true");

properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(properties, authenticator);
//session.setDebug(debug);

try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);

// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);

// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();

// attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());

// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);

// add the Multipart to the message
msg.setContent(mp);

// set the Date: header
msg.setSentDate(new java.util.Date());

// send the message
Transport.send(msg);
flag=true;


}catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
//whether mail has been sent or not.
if(flag)
{
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("success");
}
else
{
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("failure");
}
}

// Java mail authentication coding.
private class Authenticator extends javax.mail.Authenticator {
private PasswordAuthentication authentication;

public Authenticator() {
String username = "career@company.com";
String password = "****";
authentication = new PasswordAuthentication(username, password);
}

protected PasswordAuthentication getPasswordAuthentication() {
return authentication;
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java mail problem(working in intranet,but not working in iternet) sundarjothi Advanced Java 8 05-28-2008 08:00 AM
Javax.mail.MethodNotSupported Exception in java mail api namarc Advanced Java 2 05-05-2008 07:01 AM
urgent help -java mail authorization failed exception ravinder.kadiyan Advanced Java 2 04-30-2008 12:27 PM
Servlet Problem after install ^^Urgent^^ black_box Java Servlet 0 08-05-2007 02:16 AM
a problem about java mail client program lunarstyle AWT / Swing 6 06-02-2007 12:43 AM


All times are GMT +3. The time now is 08:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org