高手救命!!!我编写的发送邮件程序,发送不成功,高手指点!代码见正文!!!
红三天 2004-12-28 03:24:26 老是发送不成功
private void btnSend_Click(object sender, System.EventArgs e)
{
//创建MailMessage对象
MailMessage MyMsg = new MailMessage();
MyMsg.From = tbFrom.Text;
MyMsg.To = tbTo.Text;
MyMsg.Subject = tbSubject.Text;
MyMsg.Priority = (MailPriority)ddlPriority.SelectedIndex;
MyMsg.BodyFormat= (MailFormat)ddlBodyFormat.SelectedIndex;
MyMsg.Body = tbBody.Text;
//如果有附件则上传
HttpPostedFile hpfFile = AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
//有附件,则上传到Temp目录中
//取得文件名(不含路径)
char[] de = {'\\'};
string[] AFilename = hpfFile.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
string strPath = Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
//添加附件
MyMsg.Attachments.Add(new MailAttachment(strPath));
}
try
{
//发送
SmtpMail.SmtpServer = "smtp.sina.com.cn";
SmtpMail.Send(MyMsg);
lblShowMsg.Text ="发送成功";
tbTo.Text = "";
tbSubject.Text = "";
tbBody.Text = "";
ddlPriority.SelectedIndex = 1;
ddlBodyFormat.SelectedIndex = 0;
}
catch(Exception ee)
{
lblShowMsg.Text = "发送失败:"+ee.ToString();
}
}