mymail_pb11.5(收发邮件程序源码).仅供学习参考。
2022-04-20 18:05:50 139KB 学习 小程序 开发语言 powerbuilder
###一个带有客户端和服务器的简单聊天程序####用java编写 汇编: javac *.java 服务器使用: java Server 客户端使用: java Client 为了支持多个并发客户端,客户端被视为线程。 每次新客户端连接时,都会创建一个新的并发线程来支持该客户端的任何活动。 我使用的 Server 的初始实现没有同步任何共享数据,主要是存储消息的 ArrayList。 这导致服务器出现问题,并间接导致客户端出现问题。 如果客户端尝试在另一个客户端获取或发送消息的同时获取其消息,则消息将被锁定。 用于访问消息的同步块修复了该问题。 完成任务,如张贴。
2021-06-11 11:05:57 4KB Java
1
/* * JCatalog Project */ package com.hexiang.utils; import java.util.List; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.Properties; import javax.mail.Session; import javax.mail.Transport; import javax.mail.Message; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hexiang.exception.CatalogException; /** * Utility class to send email. * * @author hexiang */ public class EmailUtil { //the logger for this class private static Log logger = LogFactory.getLog("com.hexiang.util.EmailUtil"); /** * Send email to a single recipient. * * @param smtpHost the SMTP email server address * @param senderAddress the sender email address * @param senderName the sender name * @param receiverAddress the recipient email address * @param sub the subject of the email * @param msg the message content of the email */ public static void sendEmail(String smtpHost, String senderAddress, String senderName, String receiverAddress, String sub, String msg) throws CatalogException { List recipients = new ArrayList(); recipients.add(receiverAddress); sendEmail(smtpHost, senderAddress, senderName, recipients, sub, msg); } /** * Send email to a list of recipients. * * @param smtpHost the SMTP email server address * @param senderAddress the sender email address * @param senderName the sender name * @param recipients a list of receipients email addresses * @param sub the subject of the email * @param msg the message content of the email */ public static void sendEmail(String smtpHost, String senderAddress, String senderName, List recipients, String sub, String msg) throws CatalogException { if (smtpHost == null) { String errMsg = "Could not send email: smtp host address is null"; logger.error(e
1