if(attachment.PostedFile.FileName.Length>0)
{
//先將郵件附件上傳到服務器
FileUp.uploadFile UpPic = new uploadFile();
UpPic.iMaxSize = 1024 * 1024 * 4;
UpPic.strFilter = "gif,jpg,bmp,jpeg,doc,xls,ppt,rar,zip,exe,pdf,txt,log,ini,mdb,mdf";
string[] filenames=attachment.PostedFile.FileName.Replace("//","/").Split('/');
sFileName=filenames[filenames.Length-1];
//strImage =DateTime.Now.ToString().Replace(":","").Replace(" ","").Replace("-","")+"."+UpPic.strExt(attachment);
UpPic.strSavePathName=Server.MapPath("Attach")+"/"+sFileName;
//imagepath = strImage;
int revResult=UpPic.SaveFile(attachment);
if(revResult!=0)
{
switch(revResult)
{
case 1:
Msg("沒有上傳附件!");
break;
case 2:
Msg("您上傳的附件不能超過4M!");
break;
case 3:
Msg("上傳的附件格式不對!");
break;
case 4:
Msg("文件存放的路徑不對!");
break;
}
return;
}
//設置一個附件
System.Web.Mail.MailAttachment mailAttachment=new System.Web.Mail.MailAttachment(Server.MapPath("Attach")+"/"+sFileName);
//郵件附加上一個附件
mail.Attachments.Add(mailAttachment);
}
//SMTP服務器
//許多SMTP服務器都需要身份驗證
System.Web.Mail.SmtpMail.SmtpServer=smtpHost;
//取得用戶名
string[] AddressNames=userName.Split('');
string AddressName=AddressNames[0];
//驗證
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//登陸名
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", AddressName);
//登陸密碼
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
//發送
System.Web.Mail.SmtpMail.Send(mail);
關於.net發送郵件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
正則表達式
iversonlee
2020-02-21 04:12:22
js技巧
iversonlee
2020-02-21 04:12:22
買車流程
iversonlee
2020-02-21 04:12:22
最新版FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用簡解
iversonlee
2020-02-21 04:12:22
C#操作Excel!
iversonlee
2018-09-05 06:56:21
C# WinForm窗口最小化到系統托盤
iversonlee
2018-09-05 06:56:21
C#註冊OCX、DLL
iversonlee
2018-09-05 06:56:21
安裝包裏打進.NET Freamwork
iversonlee
2018-09-05 06:56:21
解決死鎖導致網站訪問故障的具體實例
iversonlee
2018-09-05 06:56:21
WinForm窗口系統托盤閃爍,窗口透明感
iversonlee
2018-09-05 06:56:20