用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心.Net

第三部分,构造函数和公共过程

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 15:55:33
接上
------------------------
//构造函数
public ESmtpMail()
{
    Attachments = new System.Collections.ArrayList();
}
//-----------------过程
        /// <summary>
        /// 添加邮件附件
        /// </summary>
        /// <param name="path">附件绝对路径</param>
        public void AddAttachment(string path)
        {
            Attachments.Add(path);
        }


        /// <summary>
        /// 添加一个收件人
        /// </summary>    
        /// <param name="str">收件人地址</param>
        public bool AddRecipient(string str)
        {
            str=str.Trim();
            if(str==nullstr==""str.IndexOf("@")==-1)
                return true;
            if(RecipientNum<recipientmaxnum)
            {
                Recipient.Add(RecipientNum,str);
                RecipientNum++;             
                return true;
            }
            else
            {
                errmsg+="收件人过多";
                return false;
            }
        }


        /// <summary>
        /// 添加一组收件人(不超过recipientmaxnum个),参数为字符串数组
        /// </summary>
        /// <param name="str">保存有收件人地址的字符串数组(不超过recipientmaxnum个)</param>    
        public bool AddRecipient(string[] str)
        {
            for(int i=0;i<str.Length;i++)
            {
                if(!AddRecipient(str[i]))
                {
                    return false;
                }
            }
            return true;
        }


        /// <summary>
        /// 发送邮件方法,所有参数均通过属性设置。
        /// </summary>
        public bool Send()
        {
            if(Recipient.Count==0)
            {
                errmsg="收件人列表不能为空";
                return false;
            }

            if(mailserver.Trim()=="")
            {
                errmsg="必须指定SMTP服务器";
                return false;
            }

            return SendEmail();
          
        }


        /// <summary>
        /// 发送邮件方法
        /// </summary>
        /// <param name="smtpserver">smtp服务器信息,如"username:password@www.smtpserver.com:25",也可去掉部分次要信息,如"www.smtpserver.com"</param>
        public bool Send(string smtpserver)
        {
          
            MailDomain=smtpserver;
            return Send();
        }


        /// <summary>
        /// 发送邮件方法
        /// </summary>
        /// <param name="smtpserver">smtp服务器信息,如"username:password@www.smtpserver.com:25",也可去掉部分次要信息,如"www.smtpserver.com"</param>
        /// <param name="from">发件人mail地址</param>
        /// <param name="fromname">发件人姓名</param>
        /// <param name="to">收件人地址</param>
        /// <param name="toname">收件人姓名</param>
        /// <param name="html">是否HTML邮件</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件正文</param>
        public bool Send(string smtpserver,string from,string fromname,string to,string toname,bool html,string subject,string body)
        {
            MailDomain=smtpserver;
            From=from;
            FromName=fromname;
            AddRecipient(to);
            RecipientName=toname;
            Html=html;
            Subject=subject;
            Body=body;
            return Send();
        } 

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:2,484.37500 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号