Click here to Skip to main content
15,888,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My code is:
C#
   textBoxSmtpServer.Text = "smtp.gmail.com";
         textBoxSend.Text = "lisiname@gmail.com";
         textBoxDisplayName.Text = "李斯";
         textBoxPassword.Text = "lisiname***";
         textBoxReceive.Text = "mytestname@126.com";
         textBoxSubject.Text = "测试mytest";
         textBoxBody.Text = "This is a test(测试)";
         radioButtonSsl.Checked = true;

MailMessage mailMessage = new MailMessage();
         mailMessage.From = new MailAddress(textBoxSend.Text, textBoxDisplayName.Text, System.Text.Encoding.UTF8);
         mailMessage.To.Add(textBoxReceive.Text);
         mailMessage.Subject = textBoxSubject.Text;
         mailMessage.SubjectEncoding = System.Text.Encoding.Default;
         mailMessage.Body = textBoxBody.Text;
         mailMessage.BodyEncoding = System.Text.Encoding.Default;
         mailMessage.IsBodyHtml = false;
         mailMessage.Priority = MailPriority.Normal;
 SmtpClient smtpClient = new SmtpClient();
         smtpClient.Host = textBoxSmtpServer.Text;
         smtpClient.Port = 25;
                 smtpClient.EnableSsl = radioButtonSsl.Checked;
                   smtpClient.UseDefaultCredentials = false;
         smtpClient.Credentials = new NetworkCredential(textBoxSend.Text, textBoxPassword.Text);
                   smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
         try
         {
             smtpClient.Send(mailMessage);
                       }
         catch (SmtpException smtpError)
         {
             MessageBox.Show("发送失败:" + smtpError.StatusCode
                 + "\n\n" + smtpError.Message
                 + "\n\n" + smtpError.StackTrace);
         }
         finally
         {
             mailMessage.Dispose();
             smtpClient = null;
             this.Cursor = Cursors.Default;
         }

In my xp and win7 in run well,but In win2008 r2,it shows GeneralFailure 发送邮件失败。

在 System.Net.Mail.SmtpClient.Send(MailMessage message)

How to solve it?
Posted
Comments
David_Wimbley 13-Jan-13 21:20pm    
Can we get a full stack trace? Right now it could be because its second sunday of the first month of an odd year and the moon is at the highest point in the sky.

The stack trace will probably get you an answer faster then the guess work that has to be done right now.

My initial guess is there is a firewall/windows firewall issue but again, stack trace/error msg would be wonderful
PEIYANGXINQU 14-Jan-13 0:05am    
StatusCode: GeneralFailure
Message: 在 System.Net.Mail.SmtpClient.Send(MailMessage message)
StackTrace: 在 AutoMail()(My method code is up,and the name is AutoMail)
Do win2008 R2 need to configurate something when send mail???
David_Wimbley 14-Jan-13 16:25pm    
So to me it looks like windows firewall is on your windows 2008 r2 box. Can you see if inbound/outbound traffic is allowed on port 25 on that box? Simple test would be to disabled windows firewall and then re-run your app to see if it works.
PEIYANGXINQU 17-Jan-13 13:00pm    
Usually in windows 2008 r2 box,does the port 25 is default to opened automatically?
Did I need to add port 25 in firewall to open manually or it is default to opend by the system?I using c# code,it seems I do not need to install smtp server in my system!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900