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);
{
//先将邮件附件上传到服务器
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);