Results 1 to 9 of 9
  1. #1
    sundarjothi is offline Member
    Join Date
    Apr 2008
    Location
    villupuram
    Posts
    22
    Rep Power
    0

    Default Java mail problem(working in intranet,but not working in iternet)

    Hi everyone,

    I have a little problem with my java mail coding.
    While i was using java mail coding in local netwok(intranet) properly executing.
    But i was used in internet, it is not working.
    I told my problem(java mail is not working prperly) to my server maintainer(service provider).
    They told "we loaded all mandatory jar files in Tomcat server please verify your coding"
    And told " please check your smtp protocal" and wrote code
    u shoud use smtp as 25

    other things asp and php coding are not supported in java server ..
    u should send mail coding through jsp
    Please check once & let us know if any problems !
    Please let us know the error URL / Path if you have any more problems, thanks


    please refer my coding and tell what is wrong with coding

    Properties props = System.getProperties();
    props.put("mail.smtp.host", host);
    //props.put("mail.debug", "true");
    Session session = Session.getInstance(props, null);
    //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();
    }


    please reply immediately

    thanks
    sundar

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    sundarjothi is offline Member
    Join Date
    Apr 2008
    Location
    villupuram
    Posts
    22
    Rep Power
    0

    Default Urgent

    hi thanks,
    i didnt get any exception in my program.
    program still working in local network(intranet).
    But program not working in internet(www).
    If any changes in my program ,
    please reply me.

    regrads
    sundar

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Does the smtp server that you are using to send out the email need a userid and password to access it? I use the gmail api to send mail via my java app and I need to supply my id and password, most smtp hosts require that.
    If you are not getting any exceptions I would take a look at the host you are sending thru.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    sundarjothi is offline Member
    Join Date
    Apr 2008
    Location
    villupuram
    Posts
    22
    Rep Power
    0

    Default Help

    Hi
    thanks,
    I did not use any authentication in my program .
    please verify my program and reply me
    If any changes need in my program.

    regards
    sundar

    This is my coding sample

    Properties props = System.getProperties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", 25);
    //props.put("mail.debug", "true");
    Session session = Session.getDefaultInstance(props, null);
    //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();
    }

  8. #8
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default

    Let me ask you this. What smtp gateway are you using to send your mail out?? Is it open, meaning can anyone in the world use it?
    Or is it your company smtp gateway?
    Or is it something else? Unless it is totally open, most smtp gateways have some sort of rules for using them.
    Just start by telling us that, it will help debug this issue.

  9. #9
    sundarjothi is offline Member
    Join Date
    Apr 2008
    Location
    villupuram
    Posts
    22
    Rep Power
    0

    Default Help

    Hi orchid,

    i just used company smtp server only.
    i did not give username,password in our company server( that means
    authentication not provided in my mail coding).
    I have doubt about authentication in my code.
    It may cause any problem to prevent mail send to server.

    please reply me.

    regards,
    sundar

Similar Threads

  1. JSP send mail script not working.
    By profuse in forum Java Applets
    Replies: 1
    Last Post: 05-27-2008, 07:37 AM
  2. working with mp3 in java
    By po0oker in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2007, 09:20 PM
  3. working with servlets
    By Freddie in forum Java Servlet
    Replies: 2
    Last Post: 05-15-2007, 06:50 PM
  4. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •