using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace whsvc
{
namespace CMail
{
public class CMail
{
private String servername, body, attachpath, from_address, to_address, subject, encdoing = "GB2312";
private MailMessage message = null;
private bool isBcc = false;
private SmtpClient client = null;
private String username, password;
public String Username
{
set { this.username = value; }
get { return this.username; }
}
public String Password
{
set { this.password = value; }
get { return this.password; }
}
public String Body
{
set { this.body = value; }
get { return this.body; }
}
public String Server
{
set { this.servername = value; }
get { return this.servername; }
}
public String FileName
{
set { this.attachpath = value; }
get { return this.attachpath; }
}
public String From
{
set { this.from_address = value; }
get { return this.from_address; }
}
public String To
{
set { this.to_address = value; }
get { return this.to_address; }
}
public String Subject
{
set { this.subject = value; }
get { return this.subject; }
}
public String Encoding
{
set { this.encdoing = value; }
get { return this.encdoing; }
}
public CMail(String username, String password, String servername)
{
this.username = username;
this.password = password;
this.servername = servername;
}
public CMail()
{
}
private bool parse()
{
bool success = false;
if (from_address.Length != 0)
{
if (to_address.Length != 0)
{
message = new MailMessage(this.from_address, this.to_address, subject, body);
message.BodyEncoding = System.Text.Encoding.Default;
if (this.attachpath != null)
{
if (this.attachpath.Length != 0)
{
try
{
message.Attachments.Add(new Attachment(this.attachpath));
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
}
message.Priority = MailPriority.Normal;
if (this.servername.Length != 0)
{
client = new SmtpClient(this.servername);
if (this.username.Length != 0 && this.password.Length != 0)
{
client.Credentials = new NetworkCredential(this.username, this.password);
success = true;
}
else
{
throw new Exception("用户名或密码不能为空");
}
}
else
{
throw new Exception("服务器不能为空");
}
}
else
{
throw new Exception("收件人不能为空");
}
}
else
{
throw new Exception("发件人不能为空");
}
return success;
}
public void send()
{
if (parse())
{
try
{
client.Send(message);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
}
}
}
}
小孟
分享到:
相关推荐
.NET C#SOCKET通信DEMO,断开连接事件捕捉,重连功能。 亲测可用
简单易懂的Socket发送接收实例,绝对可用; 压缩包中SocketClient为客户端,SocketTest为服务端; 可在客户端输入内容,按回车发送; 服务端会显示接收到的数据并做出回应,聊天的模式; 使用.NET Framework 2.0制作...
麻雀虽小,五脏俱全,这是一个可直接用于生产的脚手架 包含: DBHelper:数据库操作类,使用原生SQL,查询结果映射到Model,操作数据库非常方便,支持异步,...集成了自己写的Socket工具类,业务耦合较重,可以自己改
Winform窗体程序。第一个版本没有加心跳包 第二个版本可以相互检测到断网情况 适合学习,或借鉴后二次开发
c#、.NET6实现websocket协议demo,完整清晰的解析和打包示例 包含请求头解析、数据帧解析、数据帧掩码处理、数据帧打包
c# socket tcp 通信案例 c# socket tcp 通信案例 c# socket tcp 通信案例
1.基于HPSocket实现socket通讯, 实现断线自动重连、收发送消息、上线和下线提醒等功能。 2. 资源包含C#演示程序和C++dll
一个Socket入门的Domo,没写过Socket的同学可以下载看看,老手的话就算啦
Socket网络编程事例,分为客户端和服务端2个部分代码,一起运行后,可互发消息,并传送文件.
demo包含串口通讯和socket通讯,用的Serialport类和socket类,socket demo即可当客户端又可当服务端
(3)[C#].net平台下完全异步Socket编程的例子;(4)C#.net同步异步SOCKET通讯和多线程总结;(5)Socket使用简介;(6)同步套接字通信;(7)续实例解析SOCKET编程模型之异步通;(8)在C#中使用异步Socket编程实现TCP网络服务的CS...
由于在.NET中Socket通讯的建立很容易,所以本文主要介绍一个Socket的比较典型的应用的流程:客户端向服务器发送图片请求,图片服务器接收到请求, 并将服务器硬盘上的图片编码,发送到客户端,客户端得到图片数据...
基于C#语音编制的socket通信demo,socket采用长连接方式,进行聊天通信!
WPF C# 实现的客户端/服务器模式的通讯软件 要求服务器有公网IP或者局域网内运行也可 连接到运行了服务端的demo的IP即可收发消息 C#Socket网络编程C/S架构Demo即时通讯IMP2PPtoP端到端
C# 读取西门子PLC DB块数据DEMO
因为项目中需要Socket编程,就抽空写了个Socket的小示例,使用C# .NET Framework 2.0编写。
使用C#编写,web socket客户端连接源码,可用于性能测试。
SocketDemo Socket Demo 使用.net2.0(vs2005 c#),TcpClient,TcpListener
用C#实现的、基于.NET 2.0的可扩展多线程异步Socket服务器框架EMTASS 2.0(C#版)源码和Demo。有关该框架的设计说明请参考拙文:http://blog.csdn.net/hulihui/archive/2008/10/27/3158613.aspx。
一个适合初学者的控制台Socket对话程序Demo。