Hi

I have written a code for sending a mail, it was working fine before and now it hangs at tranport.send().

Can any one help, here my code
Inline Code Example Here

try {



            System.out.println("Sending Email initiated...");
            Properties properties = System.getProperties();
            properties.put("mail.smtp.auth", "false");
            properties.put("mail.smtp.starttls.enable", "true");
            properties.put("mail.smtp.host", _host);
            properties.put("mail.smtp.port", _port);
             properties.put("mail.smtp.connectiontimeout", "100000");
            properties.put("mail.smtp.timeout", "100000");
            Session session = Session.getInstance(properties,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(_emailfrom, "");
                        }
                    });
            MimeMessage message = new MimeMessage(session);
            log.debug("Sending Email from: " + _emailfrom);
            // System.out.println("Sending Email from: " + _emailfrom);
            // Set From: header field of the header.
            message.setFrom(new InternetAddress(_emailfrom));



            to_recep = _toreceipients.split(",");
            if (to_recep.length > 0) {

                for (int i = 0; i < to_recep.length; i++) {
                    message.addRecipient(Message.RecipientType.TO,
                            new InternetAddress(to_recep[i]));
                }
            }

            cc_recep = _ccreceipients.split(",");
            if (cc_recep.length > 0) {

                for (int i = 0; i < cc_recep.length; i++) {
                    if (cc_recep[i].length() > 2)
                        message.addRecipient(Message.RecipientType.CC,
                                new InternetAddress(cc_recep[i]));
                }
            }
            log.debug("Setting Subject & Content of Email");

            message.setSubject(MSG_SUBJECT + " " + getCurrentDate());
            message.setText(_message, "utf-8", "html");

            log.debug("Going to send an Email ....");
            // System.out.println("Going to send an Email ....");
            // Send message
            Transport.send(message);

            log.debug("Email send successfully....");
            // System.out.println("Email send successfully....");
        } catch (MessagingException mex) {
            mex.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
            log.debug(e.getMessage());
        }

Are you sure to posted whole code? Transport (According to Java 6 API, as this class does not exists in API 7 or 8) have to be first initialized from [constructor](http://docs.oracle.com/javaee/6/api/javax/mail/Transport.html#Transport(javax.mail.Session, javax.mail.URLName)) and only after that you can call send(message). I'm surprised you are no getting exception on compile. You should use clean build option on your project

yes it is working fine from my local system, and was working fine on server also but now it has started giving problem.
No exception is coming, i have set a timout for 1.6 min.

"now it has started giving problem" ...
this is a bit vague. Have you been able to reproduce the problem while debugging? is there logging? how do you know for sure where the code hangs? are you sure it's not your connection?

Hi
I have tested my code from local and it is working fine, i have placed loggers can it be a unix machine problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.