回 帖 发 新 帖 刷新版面

主题:[讨论]求救

问一下各位高手...
 我要做一个邮件收发系统,
 1. 怎么才能和外寄邮件服务器建立连接?
 2. 下面的代码是保存邮件附件:
void saveFile(int numAttach, String[] fileName, InputStream[] inputStream) {

String filesep = System.getProperty("file.separator");
String sfile = "";
fileFileChooser.setCurrentDirectory(new File("."));
fileFileChooser.setDialogType(JFileChooser.DIRECTORIES_ONLY
                + JFileChooser.SAVE_DIALOG);
fileFileChooser.setDialogTitle("Select Directory");
if (fileFileChooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
    return;
String pathName = fileFileChooser.getCurrentDirectory().getAbsolutePath();

// 上面那行代码一直提示:代码不可达?
这个问题怎么解决? 望各位高手指点!!!不胜感激
this.repaint();
try {
     for (int j = 0; j < numAttach; j++) {
    File file = new File(pathName + filesep + fileName[j]);
          FileWriter out = new FileWriter(file);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStrea[j]));
BufferedWriter bw = new BufferedWriter(out);
String line;
while ((line = br.readLine()) != null) {
    bw.write(line);
    bw.newLine();
            }
    bw.flush();
    bw.close();
          out.close();
    sfile = sfile + pathName + filesep + fileName[j] + linesep;
                }
    String dMessage = sfile + "attachments have been saved to "+ pathName;
    String dTitle = "Save Attachment";
    int dType = JOptionPane.INFORMATION_MESSAGE;
    JOptionPane.showMessageDialog(null, dMessage, dTitle, dType);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    }
  }

回复列表 (共5个回复)

沙发

呵呵,各位高手,请赐教!!!!

板凳

[quote]if (fileFileChooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
    return;
String pathName = fileFileChooser.getCurrentDirectory().getAbsolutePath();

// 上面那行代码一直提示:代码不可达?
这个问题怎么解决? 望各位高手指点!!!不胜感激
[/quote]
code after return, of course 代码不可达.

My guess, put that line outside of if {} block.

3 楼

[quote] 怎么才能和外寄邮件服务器建立连接?[/quote]

Do a google search"java mail example", you will find many runnable code.

4 楼

呵呵,谢谢,我一直没发现这个问题....搞得好郁闷的!!!
谢谢这位高手..../^_^

5 楼

高手,又有问题请教拉..
 当我点击发送按钮,Debug 出现下面的异常:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP:[color=FF00FF] trying to connect to host "mail.163.com", port 25, isSSL false
javax.mail.MessagingException: Unknown SMTP host: mail.163.com;
  nested exception is:
    java.net.UnknownHostException: mail.163.com[/color]
    
呵呵,这个问题怎么处理, mail.163.com ,我联网也发送不了......也是出现上面的错误
这个外寄邮件服务器 是在自己机子上配置,还是Internet 上本来就已经存在了?
  期待回复......
    
    

我来回复

您尚未登录,请登录后再回复。点此登录或注册