using System;
using jmail;
using System.Collections;
namespace TYM.Com.MyMail
{
?///
?/// 邮件发送接收类
?///
?public class Mail
?{
??///
??/// 邮件类的构造函数
??///
??public Mail()
??{
??}
??///
??/// 邮件模型
??///
??public MailModel model = new MailModel();
??///
??/// 发送邮件
??///
??/// 返回值为布尔型,判断发送是否成功
??public? bool SendMail()
??{
???try
???{
????jmail.MessageClass myMail = new jmail.MessageClass();
????myMail.Charset="GB2312";//邮件使用字符集
????myMail.From = model.From; //邮件发送者邮件地址
????myMail.FromName = model.FromName; //邮件发送者名称
????myMail.AddRecipient(model.To,model.ToName,"");//添加邮件接收者名称以及邮件地址
????
????myMail.Subject = model.Subject; //邮件主题
????myMail.Body = model.Body; //邮件内容
????// 判断是否有附件
????if(model.FileName != "")
????{
?????myMail.AddAttachment(model.FileName,false,model.FileType);//添加邮件附件
????}
????myMail.Priority =model.Priority; //邮件的紧急程度
????myMail.MailServerUserName = model.MailServerUserName; //登陆邮件服务器的用户名
????myMail.MailServerPassWord = model.MailServerPassWord; //登陆邮件服务器的密码
????return myMail.Send(model.MailDomain,false); //邮件服务器地址(例:smtp.163.com)
???}
???catch(Exception ex)
???{
????throw new Exception(this+".SendMail():"+ex.ToString());
???}
??}
??///
??/// 获取邮件列表
??///
??/// 邮件服务器用户名
??/// 邮件服务器用户密码
??/// 服务器地址
??/// 返回邮件列表
??public ArrayList GetMail(string userName,string pwd,string server)
??{
???try
???{
????
????jmail.POP3Class mail = new POP3Class();
????mail.Connect(userName,pwd,server,110);//连接POP3服务器
????int i = mail.Count;//邮件数量
????ArrayList list = new ArrayList();
????for(int j=0;j
????{
?????jmail.MessageClass m = (MessageClass)mail.DownloadSingleMessage(j+1);
?????list.Add(m);
????}
????mail.Disconnect();
????
????return list;
???}
???catch
???{
????throw new Exception("您的邮箱配置信息出错!");
???}
??}
?}
}