C# 发送邮件

来源:互联网 发布:js怎么用 编辑:程序博客网 时间:2024/06/09 18:56

SmtpClient MailAddress MailMessage     

            SmtpClient smtp = new SmtpClient();
            smtp.Host = this.txtSmtp.Text;
            smtp.Port = int.Parse(this.txtPort.Text);
            smtp.Credentials = new NetworkCredential(this.txtAccount.Text, this.txtPwd.Text);
            smtp.EnableSsl = false;
            smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(this.txtFrom.Text);
            mail.Subject = this.txtSubject.Text;
            mail.BodyEncoding = Encoding.UTF8;
            mail.IsBodyHtml = false;
            mail.Body = this.txtContent.Text;
            string[] to = this.txtTo.Text.Split('|');
            foreach (string item in to)
            {
                mail.To.Add(item);
            }

            try
            {
                smtp.SendAsync(mail,mail);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.ToString());
            }

0 0
原创粉丝点击