asp.Net
发布时间:2022-04-07 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用System.Net.Mail中的SMTP发送邮件(带附件),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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
方法,因此应用程序必须调用https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.smtpclient.dispose?view=netframework-4.7.2" data-linktype="relative-path">Dispose以显式释放资源。
https://cn.js-code.com/res/2019/02-03/17/1c53668bcee393edac0d7b3b3daff1ae.gif" alt="">
![](<a href=)
https://cn.js-code.com/res/2019/02-03/17/405b18b4b6584ae338e0f6ecaf736533.gif" alt="">
mailsend = Task Send(jectE)
{
SmtpClient smtp = SmtpClient();
smtp.EnableSsl = false;
smtp.Host = ;
smtp.port = ; password");
Mailmessage msg = Mailmessage();message对象
msg.Priority = MailPriority.High;
msg.To.Add(l.com); );
msg.bcc.Add();
String filename = na = request.Files.AllKeys;http请求过来的文件
( item {
httpPostedFileBase file = request.Files[item] httpPostedFileBase;
filename =Name);
Attachment attach = Attachment(fileName);
ContentDisposition dispo = attach.ContentDisposition;
dispo.CreationDate =m.IO.File.GetCreationTime(fileName);
dispo.ModificationDate =m.IO.File.GetLastWriteTime(fileName);
dispo.ReadDate =m.IO.File.GetLastAccessTime(fileName);
msg.Attachments.Add(attach);
msg.From = MailAddress(,);
msg.Subject = msg.SubjectEncoding =m.Text.Encoding.UTF8;
msg.body = msg.bodyEncoding =m.Text.Encoding.UTF8;
smtp.SendCompleted += );
String userState = smtp.SendAsync(msg,userStatE);
(mailsend==false)
{
);
Response.Write();
client_SendCompleted(jectE)
{
String token =(String {
Response.Write(String.Format({0} Send canceled.);
(e.Error != {
Response.Write(String.Format({0}] {1}String()));
{
Response.Write(message Send.);
mailsend = }
感谢您的观看,您的
大佬总结
以上是大佬教程为你收集整理的使用System.Net.Mail中的SMTP发送邮件(带附件)全部内容,希望文章能够帮你解决使用System.Net.Mail中的SMTP发送邮件(带附件)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。