利用System.Net.Mail 的SmtpClient发送邮件

/// <param name="toAddr">接受人地址</param>
        /// <param name="Cc">抄送</param>
        /// <param name="Mcc">密送</param>
        /// <param name="from">发送人地址</param>
        /// <param name="content">邮件内容</param>
        /// <param name="subject">邮件标题</param>
        /// <param name="attach">附件</param>
        /// <param name="Pwd">密码</param>
        public void SendMailByPlainFormat(string toAddr, string Cc, string Mcc, string from, string content, string subject, string attach,string Pwd)
        {
            MailMessage mailobj = new MailMessage();
            mailobj.From = new MailAddress(from);//发件人
            //mailobj.To.Add(toAddr); //收件人或下面的收件人组


               #region 收件人组
                ArrayList list = new ArrayList();
                list.Add("**@163.com");
                list.Add("**@qq.com");
                for (int i = 0; i < list.Count; i++)
                {
                    MailAddress toAddress = new MailAddress(list[i].ToString());
                    mailobj.To.Add(toAddress);//收件人
                }
                #endregion

 

            if (Cc != "")
                mailobj.CC.Add(Cc);  //抄送
            if (Mcc != "")
                mailobj.Bcc.Add(Mcc);  //密送
            mailobj.Priority = MailPriority.High;  //发送优先级
            mailobj.Subject = subject; //主题
            mailobj.Body = content;   //内容
            mailobj.IsBodyHtml = true; //内容是否可以为html形式
            mailobj.BodyEncoding = Encoding.Default;
            if (attach != "")
            {
                char[] delim = new char[] { ';' };
                foreach (string substr in attach.Split(delim))
                {
                    Attachment MyAttach = new Attachment(substr);
                    //MailAttachment MyAttach = new MailAttachment(substr);
                    mailobj.Attachments.Add(MyAttach);

                }
            }

            SmtpClient smtp = new SmtpClient();
            //smtp.Host = this.server;  //服务器
            //smtp.Port = this.port;    //端口       
            //smtp.Credentials = new System.Net.NetworkCredential(this.user, this.password); //用户名和密码
            smtp.Host = "smtp."+from.Substring(from.IndexOf("@")+1);  //服务器
            smtp.Port = 25;    //端口       
            smtp.Credentials = new System.Net.NetworkCredential(from, Pwd); //用户名和密码
            smtp.Send(mailobj);
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值