tags:

views:

113

answers:

2

My code runs on a windows server on my machine, but as I upload the same class file to the Linux server machine it does not work.

As there is no error generation, I can't get the exact problem..

See my code below if you could help me.

public static String myemail = "[email protected]", //username
mypassword = "*************", //password
myhost = "smtp.abc.com", // smtp address
myport = "234", // port address
mysubject = "Hello",
mytext = "this is just a test mail";


public String mail(String recp)
{

    Properties pro = new Properties();
    pro.put("mail.smtp.user", myemail);
    pro.put("mail.smtp.host", myhost);
    pro.put("mail.smtp.port", myport);
    pro.put("mail.smtp.starttls.enable","true");
    pro.put("mail.smtp.auth", "true");
    pro.put("mail.smtp.debug", "true");
    pro.put("mail.smtp.socketFactory.port",myport);


    SecurityManager security = System.getSecurityManager();

    try
    {
        Authenticator authen = new SMTPConfig();
        Session session = Session.getInstance(pro, authen);
        session.setDebug(true);

        MimeMessage msg = new MimeMessage(session);
        msg.setText(mytext);
        msg.setSubject(mysubject);
        msg.setFrom(new InternetAddress(myemail));
        msg.addRecipient(Message.RecipientType.TO, new
        InternetAddress(recp));
        Transport.send(msg);
    }

    catch (Exception ex)
    {
        ex.printStackTrace();
    }

    return null;

}

private class SMTPConfig extends javax.mail.Authenticator
{

    public PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(myemail, mypassword);
    }

}
A: 

Did you try to run your code as the superuser? Maybe its just some unprivileged user problem.

+1  A: 

Try

pro.put("mail.debug", "true"); instead of pro.put("mail.smtp.debug", "true");

this may capture all mail errors and then you can analyse..

lakshmanaraj