Click here to Skip to main content
13,146,014 members (44,477 online)
Rate this:
Please Sign up or sign in to vote.
My code is:
      textBoxSmtpServer.Text = "";
            textBoxSend.Text = "";
            textBoxDisplayName.Text = "李斯";
            textBoxPassword.Text = "lisiname***";
            textBoxReceive.Text = "";
            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.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;
            catch (SmtpException smtpError)
                MessageBox.Show("发送失败:" + smtpError.StatusCode
                    + "\n\n" + smtpError.Message
                    + "\n\n" + smtpError.StackTrace);
                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 13-Jan-13 15:15pm
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100