邮件发送老出现问题,请高手指点
//程序如下using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Util;
using System.Web.Mail;
namespace _51aspxMail
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
format.Items.Add(new ListItem("文本", "0"));
format.Items.Add(new ListItem("HTML", "1"));
format.Items[0].Selected = true;
fromMail.Text = "suhui0312@yahoo.com.cn"; //发送方邮件
fromMail.Enabled = false;
}
}
private bool SendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
{
try
{
MailMessage myMail = new MailMessage();
myMail.From = fromMail;
myMail.To = fromMail;
myMail.Cc = ccMail;
myMail.Bcc = bccMail;
myMail.Subject = subject;
myMail.Body = body;
myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;
//附件
string ServerFileName = "";
if (this.upfile.PostedFile.ContentLength != 0)
{
string upFileName = this.upfile.PostedFile.FileName;
string[] strTemp = upFileName.Split('.');
string upFileExp = strTemp[strTemp.Length - 1].ToString();
ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
this.upfile.PostedFile.SaveAs(ServerFileName);
myMail.Attachments.Add(new MailAttachment(ServerFileName));
}
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "suhui0312@yahoo.com.cn"); //发送方邮件帐户
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "03125074625"); //发送方邮件密码
SmtpMail.SmtpServer = "smtp.mail.yahoo.com.cn";
SmtpMail.Send(myMail);
return true;
}
catch
{
return false;
}
}
protected void send_Click(object obj, EventArgs e)
{
try
{
bool flag = SendMail(fromMail.Text, toMail.Text, ccMail.Text, bccMail.Text, subject.Text, body.Text, format.SelectedValue);
if (flag == true)
{
Response.Write("<script>alert('发送成功!');</script>");
}
else
{
Response.Write("<script>alert('发送失败!');</script>");
}
}
catch(Exception ex)
{ ///跳转到异常错误处理页面
Response.Write(ex.Message.Replace("<br>","").Replace("\n",""));
}
}
}
}
//运行后老是发送失败 --------------------编程问答-------------------- 分少了点 哈哈
帮UP --------------------编程问答-------------------- 各位高手帮忙看看,主要是什么问题
补充:.NET技术 , ASP.NET