Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WinXP C#3.0 C# Windows C#4.0 Win7 , +
My code is:
 
      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 13-Jan-13 15:15pm
Comments
David_Wimbley at 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 at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 509
1 Nirav Prabtani 298
2 OriginalGriff 215
3 _Amy 165
4 Abhinav S 160
0 OriginalGriff 7,715
1 Sergey Alexandrovich Kryukov 6,911
2 Maciej Los 3,954
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
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