当前位置:编程学习 > C#/ASP.NET >>

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

答案:接上
------------------------
//构造函数
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==null||str==""||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>
     &

上一个:第二部分,公共属性
下一个:例子

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,