⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtpserver.java

📁 基于java的电子邮件群发系统,基于java的电子邮件群发系统
💻 JAVA
字号:
package com.cwq.batchmail.mail;


/*
 * Copyright (c) 1998 Computer Mutter All Rights Reserved.
 */

import java.net.*;
import java.util.Hashtable;
import java.io.*;

import com.cwq.batchmail.log.Logger;
import com.cwq.batchmail.util.NSLookup;

/**
 * Smtp3Server Creates an ServerSocket on port 25 and waits for clients to be
 * connected. Then starts for every connection an Thread with an Smtp3Connection
 * class. The Server compares the host keyword from the mail.cfg configuration
 * file with the to statement from the client. Are they equal the E-Mail will be
 * local stored in the user directory. Are the not equal the E-Mail will be
 * stored in the homeDir\Queue directory.
 * 
 * This is an application !
 * 
 * (c) 1998 Computer Mutter computer@mutter.com
 */

public class SmtpServer extends Thread {
	private ServerSocket pSmtpSocket;

	private String pDomain;
	private NSLookup nsLookup;
	private Logger logger = null;
	
	private boolean running = false;

	public boolean isRunning() {
		return running;
	}

	public SmtpServer(Logger logger, String domain) {
		setLogger(logger);
		setDomain(domain);
		
		nsLookup = new NSLookup();

		try {
			setSmtpSocket(new ServerSocket(25));
			this.start();
			running = true;
		} catch (IOException exp) {
			handleException(exp);
			if( logger != null )
				logger.info("error cannot start Java SmtpServer: " + exp);
		}
	}

	public static void main(java.lang.String[] args) {

		System.out
				.println("Java SmtpServer Running ...");

		try {
			new SmtpServer(null, "mytestqq.com");
		} catch (Exception exp) {
			System.err.println(exp);
		}

	}

	public void run() {
		Socket client;
		for (;;) {
			try {
				// System.out.println("check port: "+smtpSocket.getLocalPort()
				// );
				client = getSmtpSocket().accept();
				//System.out.println("awfafafa------- " + client.hashCode());
				SmtpServerThread t = new SmtpServerThread(getDomain(), client, nsLookup);
				t.setLogger(logger);
				t.start();
			} catch (IOException exp) {
				handleException(exp);
				if( logger != null )
					logger.info("error checking port");
				break;
			} catch(Exception ex) {
				
			}
			// System.out.println("new connection from: "+client );
		}
	}

	public void setDomain(String domain) {
		pDomain = domain;
	}

	public void setSmtpSocket(ServerSocket host) {
		pSmtpSocket = host;
	}

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}
	
	public String getDomain() {
		return pDomain;
	}

	public ServerSocket getSmtpSocket() {
		return pSmtpSocket;
	}

	private void handleException(Throwable exp) {

		exp.printStackTrace();
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -