System.Net.Mail
使用简单邮件传输协议SMTP异步发送邮件
想要实现SMTP发送邮件,你需要了解这些类
SmtpClient :使用配置文件设置来初始化 SmtpClient类的新实例。
它包含以下属性:
Host:设置用于SMTP服务的主机名或主机IP;
Port:设置用于SMTP服务的端口(一般设置为25);
Credentials:身份验证;
Send:直接发送邮件;
SendAsync:异步发送邮件(不阻止调用线程)。
MailMessage:表示一封电子邮件。
它包含以下属性:
Attachment:表示文件附件;
CC:抄送;
Subject:主题;
From:发件人
Priority:优先级;
Body:正文;
BodyEncoding:Content-type。
此外 SmtpClient类不具有Finalize
方法,因此应用程序必须调用以显式释放资源。
mailsend = Task Send(
SmtpClient smtp = SmtpClient();
smtp.EnableSsl = ;
smtp.Host = ;
smtp.Port = ;
MailMessage msg = MailMessage();
msg.Priority = MailPriority.High;
msg.To.Add();
msg.Bcc.Add();
fileName = na = Request.Files.AllKeys;
( item HttpPostedFileBase file = Request.Files[item] fileName = Attachment attach = Attachment(fileName);
ContentDisposition dispo = attach.ContentDisposition;
dispo.CreationDate = dispo.ModificationDate = dispo.ReadDate = msg.Attachments.Add(attach);
msg.From = MailAddress(,);
msg.Subject = msg.SubjectEncoding = msg.Body = msg.BodyEncoding = smtp.SendCompleted += userState = smtp.SendAsync(msg,userState);
(mailsend==)
Response.Write(
client_SendCompleted( token =( Response.Write(.Format( (e.Error != Response.Write(.Format(
Response.Write( mailsend = }