不得不来CSDN问了,C#发邮件问题!!!!急!

iMIssINGu 2009-04-21 12:48:46
用.net 2.0 的system.net.mail 发邮件 gmail的 下面代码没有提示错误 就是运行之后没反应 !!!!
MailMessage testMail = new MailMessage();
testMail.From = new MailAddress(txtBoxFrom.Text);
testMail.To.Add(new MailAddress(txtBoxTo.Text));
testMail.Subject = txtBoxSubject.Text;
testMail.BodyEncoding = System.Text.Encoding.UTF8;
testMail.IsBodyHtml = true;
testMail.Body = richTxtBoxContent.Text;
testMail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient(txtBoxSmtpSever.Text,587);//或者是587、465
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("****@gmail.com", "****");
client.EnableSsl = true;

try
{
client.Send(testMail);
}
catch (Exception ee)
{
richTxtBoxContent.Text = ee.Message;
}

没人给我说我会疯掉的!!!!
...全文
128 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxm3630478 2009-04-21
  • 打赏
  • 举报
回复
可能是邮件帐号的问题,新帐号是发不出去的,最好用企业邮箱和一些经常使用并且邮箱使用时间较长的ID

jdhlowforever 2009-04-21
  • 打赏
  • 举报
回复
学习下.跟ASP差不多.SMTP的都差不多吧.
I_loveCoding 2009-04-21
  • 打赏
  • 举报
回复
这么多的思路 ,值得学习一下。
路人乙e 2009-04-21
  • 打赏
  • 举报
回复
条件:from == username
xiaojing7 2009-04-21
  • 打赏
  • 举报
回复
增加个提示就OK了
zjs1109 2009-04-21
  • 打赏
  • 举报
回复
STMP问题吧。。
zzxap 2009-04-21
  • 打赏
  • 举报
回复
断点一下看执行到哪里看看
chuxue1342 2009-04-21
  • 打赏
  • 举报
回复
代码貌似没有问题!为什么不去邮箱里面看看~~
liujiayu10 2009-04-21
  • 打赏
  • 举报
回复
用JMAIL4吧 网上例子多的是,NET自带的东西都不太好用的
pc_funning 2009-04-21
  • 打赏
  • 举报
回复
你发送完输出个提示看看,应该是发过去了
pennymay 2009-04-21
  • 打赏
  • 举报
回复

MailMessage testMail = new MailMessage();
testMail.From = new MailAddress(txtBoxFrom.Text);
testMail.To.Add(new MailAddress(txtBoxTo.Text));
testMail.Subject = txtBoxSubject.Text;
testMail.BodyEncoding = System.Text.Encoding.UTF8;
testMail.IsBodyHtml = true;
testMail.Body = richTxtBoxContent.Text;
testMail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient(txtBoxSmtpSever.Text,587);//或者是587、465
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("****@gmail.com", "****");
client.EnableSsl = true;

try
{
this.Cursor = Cursors.WaitCursor;
client.Send(testMail);
this.Cursor = Cursors.Default;
MessageBox.Show("发送成功");
}
catch (Exception ee)
{
this.Cursor = Cursors.Default;
richTxtBoxContent.Text = ee.Message;
}

wonsoft 2009-04-21
  • 打赏
  • 举报
回复
兄弟,是不是你发送完毕之后没有提示?所以你觉得没有反应哦?
tjccn_wx 2009-04-21
  • 打赏
  • 举报
回复
没反应去看邮箱吧,发成功了应该。我刚还以为gmail又不支持smtp了,还试了一下能发
我的代码是vb的跟你的基本一样


Dim message As New System.Net.Mail.MailMessage

message.From = New MailAddress("xxx@gmail.com") '"Your DisplayName"
message.To.Add(New MailAddress("xxx@hotmail.com")) ' the email you want to send email to
Message.Subject = "A test email"

message.IsBodyHtml = True
message.BodyEncoding = System.Text.Encoding.UTF8
Message.Body = "this is just a simple test!<br> Jack"
message.Priority = MailPriority.High

Dim client As New SmtpClient("smtp.gmail.com", 587) ' // 587;//Gmail使用的端口
client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxx") ' // Your user name & password
client.EnableSsl = True ' //经过ssl加密

Try
client.Send(message)
Debug.Print("邮件发送到" + message.To.ToString() + "<br>")

Catch ex As Exception
Debug.Print(ex.Message + "<br>" + ex.InnerException.Message)

End Try

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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