发动邮件功能 错误

sky911911 2009-12-24 01:33:36
An existing connection was forcibly closed by the remote host


我只是简单的写了这么几句

String ToAddress = "*************@qq.com";

MailMessage mm = new MailMessage(UsersEmail.Text, ToAddress);
mm.Subject = Subject.Text;
mm.Body = Body.Text;
mm.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();


smtp.Send(mm);

错误显示在这一行 smtp.Send(mm);
...全文
111 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxcv12zxcv 2009-12-24
  • 打赏
  • 举报
回复
smtp.qq.com 25
chenjianyong94 2009-12-24
  • 打赏
  • 举报
回复
如果:你选择的是jmail主键发送电子邮件,除QQ邮箱的发送不成功,其他的应该都成功,这个问题我还在解决中,准备重新写个主键,好像不支持服务,QQ要求身份验证。
bydxyj 2009-12-24
  • 打赏
  • 举报
回复
有可能是防火墙阻止了。
在防火墙里设置一下,再试试~
sky911911 2009-12-24
  • 打赏
  • 举报
回复
ok 谢谢大家了 我现在在公司做的测试 可能是因为公司有防火墙的原因?
fwacky 2009-12-24
  • 打赏
  • 举报
回复

private void SendMail()
5 {
6 MailMessage m = new MailMessage();
7
8 /**////发件人地址
9 m.From = tbFrom.Text;
10
11 /**////收件人地址
12 m.To = tbTo.Text;
13
14 /**////邮件主题
15 m.Subject = tbSubject.Text;
16
17 /**////邮件内容
18 m.Body = tbBody.Text;
19
20 /**////优先级
21 switch(ddlp.SelectedIndex)
22 {
23 case 0:
24 m.Priority = MailPriority.High;
25 break;
26 case 1:
27 m.Priority = MailPriority.Low;
28 break;
29 default:
30 m.Priority = MailPriority.Normal;
31 break;
32 }
33
34 /**////设置邮件格式
35 if(ddlp.SelectedIndex==0)
36 m.BodyFormat = MailFormat.Text;
37 else
38 m.BodyFormat = MailFormat.Html;
39
40 /**////设置服务器
41 if(tbServer.Text!="")
42 {
43 SmtpMail.SmtpServer = tbServer.Text;
44 }
45
46 /**////以下处理附件
47 string strFileName = FileSelect.PostedFile.FileName;
48 if(strFileName!="")
49 m.Attachments.Add(new MailAttachment(strFileName));
50
51 /**////发送邮件
52 SmtpMail.Send(m);
53 }

fanliang11 2009-12-24
  • 打赏
  • 举报
回复
这样写才是正确的。。呵呵。。自己写了一个发送邮件类。。这个代码就注释了。。刚从项目拷来的。。
fanliang11 2009-12-24
  • 打赏
  • 举报
回复

//mail.From = ""; //发件人邮箱
//mail.To = Request.QueryString["id"]; //收件人邮箱
//mail.Subject = "测试邮件"; //邮件主题
//mail.BodyFormat = System.Web.Mail.MailFormat.Text; //邮件类型
//mail.Body = "邮件内容\r\n这是一封测试邮件"; //邮件内容 //需要验证
//mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //发件服务器登陆名,一般为发件地址@前面的内容,有的邮件服务器可能是和发件邮箱一样
//mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername", ""); //登陆密码,一般为发件邮箱的登录密码
//mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword", ""); //发件服务器名称,可为IP地址
//System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com"; //发送邮件
//mail.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
//System.Web.Mail.SmtpMail.Send(mail);
fanliang11 2009-12-24
  • 打赏
  • 举报
回复
Smtp服务器装了没有。。设置了没有。。还有端口正确吗?
sky911911 2009-12-24
  • 打赏
  • 举报
回复
Server Error in '/' Application.
An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Source Error:
sky911911 2009-12-24
  • 打赏
  • 举报
回复
我在web。config里面设置了啊
宝_爸 2009-12-24
  • 打赏
  • 举报
回复
Smtp服务器设置成什么了?
就是smtp.Host 的值
huming_h 2009-12-24
  • 打赏
  • 举报
回复
具体什么错误信息,

smtp需要输入用户名和密码吧。

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧