2009-03-24 10 views
0

私のコードはマシン上のWindowsサーバー上で動作しますが、同じクラスファイルをLinuxサーバーマシンにアップロードすると動作しません。Javaでメールを送信中に問題が発生しました

エラーの発生はありませんので、私はあなたが私を助けることができれば

は、以下の私のコードを参照してください。..正確な問題を取得することはできません。

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); 
    } 

} 
+0

フォーマットコード! –

答えて

0

コードをスーパーユーザーとして実行しようとしましたか?たぶんその特権のないユーザーの問題です。

1

pro.put( "mail.debug"、 "真")を試してみてください。 pro.put( "mail.smtp.debug"、 "true")の代わりに。

これはすべてのメールのエラーをキャプチャし、分析することができます..

関連する問題