当前位置: 代码迷 >> ASP.NET >> 关于邮件的发送有关问题
  详细解决方案

关于邮件的发送有关问题

热度:9477   发布时间:2013-02-25 00:00:00.0
关于邮件的发送问题?
各位好,向大家请都个关于邮件发送问题,我写了个发送邮件的小测试,结果老是出现问题,想请大家帮忙看一下.下面是我的代码:
private void Page_Load(object sender, System.EventArgs e)
  {
 
  MailMessage MailObj=new MailMessage ();
  MailObj.From="mymail@yahoo.com.cn"; //这是我的邮箱
  MailObj.To="mymail@yahoo.com.cn";

  MailObj.BodyFormat=MailFormat.Text;
  MailObj.Priority=MailPriority.Low;
  MailObj.Subject="这是一个测试项目";
  MailObj.Body="这是一个测试项目";
  SmtpMail.SmtpServer="";
  SmtpMail.Send(MailObj);
 
  }
“SendUsing”配置值无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Runtime.InteropServices.COMException: “SendUsing”配置值无效。 

不知道是怎么回事,请知道的告诉一声,先在此谢谢各位了,在线等待各位的帮忙.
解决立即结贴

------解决方案--------------------------------------------------------
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";//设置服务器
client.Credentials = new System.Net.NetworkCredential(“发件人邮箱”,“ 发件人邮箱密码");
client.Send(MailObj);
------解决方案--------------------------------------------------------
给你一个发邮件的方法
/// <summary>
/// 发送信息邮件
/// </summary>
private static string SendMail(string MailFrom, string MailTo, string MailTocc, string Subject, string Content, string PRI, string MailServer)
{
if(bolIsSucceed)
{
Subject += "转档成功";
}
else
{
Subject += "转档失败";
}
if (MailFrom!=null && MailFrom.Trim()!="" && MailTo!=null && MailTo.Trim()!="" && Subject!=null && Subject.Trim()!="" && MailServer!=null && MailServer.Trim()!="")
{
try
{
MailMessage MyEmail = new MailMessage();
MyEmail.From = MailFrom;
MyEmail.To = MailTo;
if (MailTocc!=null && MailTocc.Trim()!="")
{
MyEmail.Cc = MailTocc;
}
MyEmail.Subject = Subject;
MyEmail.Body = Content;
SmtpMail.SmtpServer = MailServer.Trim();
MyEmail.BodyFormat = MailFormat.Html;
if (PRI!=null && PRI.Trim()!="0")
{
if (PRI=="1")
{
MyEmail.Priority = MailPriority.Normal;
}
else
{
MyEmail.Priority = MailPriority.Low;
}
}
else
{
MyEmail.Priority = MailPriority.High;
}

SmtpMail.Send(MyEmail);
return "1";
}
catch(Exception eer)
{
return eer.Message;
}
}
else
{
return "Email必要参数缺失";
}
}

------解决方案--------------------------------------------------------
我最近也在做.刚好有个成功的!!你拿去用吧!
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 
Dim mg As MailMessage = New MailMessage()
mg.From = New MailAddress("chuxue1342@qq.com") '发件人邮箱
mg.To.Add("chuxue1342@avl.com.cn") '收件人邮箱
mg.Subject = "邮件测试" '邮件主题
mg.Body = "测试邮件,,内容为空" '邮件内容
mg.BodyEncoding = System.Text.Encoding.UTF8 '内容编码
mg.IsBodyHtml = True '是否支持HTML格式
mg.Priority = MailPriority.High '优先级别
mg.Attachments.Add(New Attachment("c:\ps.txt")) '添加附件
Dim smtp As SmtpClient = New SmtpClient()
  相关解决方案