protected void btnSend_Click(object sender, EventArgs e)
{
if (this.txtReceiver.Text != string.Empty && this.txtSender.Text != string.Empty)
{
//创建邮件
MailMessage myMail = new MailMessage(this.txtSender.Text.Trim(), this.txtReceiver.Text.Trim(), this.txtSubject.Text.Trim(), this.txtContent.Text.Trim());
myMail.Priority = System.Net.Mail.MailPriority.High;这里有什么作用?
//创建附件对象
string sFilePath = this.upFile.PostedFile.FileName;这里是不是指选择附件的名字?;
FileInfo fi = new FileInfo(sFilePath);
if(fi.Exists) 这两名什么意思? {
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(sFilePath, System.Net.Mime.MediaTypeNames.Application.Octet);这个是不是指附件的类型?
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;这名什么意思?
disposition.CreationDate = System.IO.File.GetCreationTime(sFilePath);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(sFilePath);
disposition.ReadDate = System.IO.File.GetLastAccessTime(sFilePath);
myMail.Attachments.Add(myAttachment);
}
//发送邮件
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.126.com ", 25);
client.Credentials = new System.Net.NetworkCredential(this.txtSUser.Text.Trim(),this.txtEPwd.Text.Trim());
client.Send(myMail);
------解决方案--------------------------------------------------------
myMail.Priority = System.Net.Mail.MailPriority.High;//设置邮件优先级,发出后邮件会显示感叹号加急或下箭头缓慢等标识
//创建附件对象
string sFilePath = this.upFile.PostedFile.FileName;//获取上传控件文件名;
FileInfo fi = new FileInfo(sFilePath);
if(fi.Exists) //判断文件是否存在 {
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(sFilePath, System.Net.Mime.MediaTypeNames.Application.Octet);//指定文件类型,不确定可选此项
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;//设置文件属性,MIME类型