通过C#发送电子邮件无法正常工作。目标机器主动拒绝连接 [英] Sending email trough C# not working. Target machine actively refusing connection

查看:73
本文介绍了通过C#发送电子邮件无法正常工作。目标机器主动拒绝连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

       很长一段时间以来我没有编写任何代码,我的一个朋友让我创建了一个按下按钮发送电子邮件的应用程序。我相信我的代码一点也不差,但是出于一个奇怪的原因,我的交换
服务器拒绝我访问,总是给我<< SocketException无法建立连接,因为 目标机器主动拒绝它> ;>

        Been a long time since I did not code anything and a friend of mine asked me to create an application that send an email on the press of a button. I believe my code is not bad at all, but for a weird reason my exchance server is refusing me acces, always giving me the <<SocketException No connection can be made because the target machine actively refuse it>>

        我使用我的交换服务器的确切名称,所以他有什么不对,为什么允许outlook发送电子邮件而不是我的自定义应用?任何人都有任何提示??

         I use the exact name of my exchange server, so what wrong with him , why allow outlook to send email but not my custom app ?? Anyone have any hint ??

              谢谢

               Thanks

这是我的代码


private void button1_Click(object sender, EventArgs e)
    {
      string To = "my email adress";
      string From = "my email adress";
      string Subject = "Test";
      string Body = "Test";      

      // create the email message
      MailMessage completeMessage = new MailMessage(From, To, Subject, Body);
      

      // create smtp client at mail server location
      SmtpClient client = new SmtpClient("my exchange server");

      // add credentials and SSL
      client.UseDefaultCredentials = true;
      client.EnableSsl = true;
      client.DeliveryMethod = SmtpDeliveryMethod.Network;
      

      try
      {
        // send message
        client.Send(completeMessage);
      }
      catch (Exception)
      {
        throw;
      
}

推荐答案


嗨伙计

Hi guys

       很长一段时间以来我没有编写任何代码,我的一个朋友让我创建了一个按下按钮发送电子邮件的应用程序。我相信我的代码一点也不差,但是出于一个奇怪的原因,我的交换
服务器拒绝我访问,总是给我<< SocketException无法建立连接,因为 目标机器主动拒绝它> ;>

        Been a long time since I did not code anything and a friend of mine asked me to create an application that send an email on the press of a button. I believe my code is not bad at all, but for a weird reason my exchance server is refusing me acces, always giving me the <<SocketException No connection can be made because the target machine actively refuse it>>

        我使用我的交换服务器的确切名称,所以他有什么不对,为什么允许outlook发送电子邮件而不是我的自定义应用?任何人都有任何提示??

         I use the exact name of my exchange server, so what wrong with him , why allow outlook to send email but not my custom app ?? Anyone have any hint ??

              谢谢

               Thanks

这是我的代码


private void button1_Click(object sender, EventArgs e)
  {
   string To = "my email adress";
   string From = "my email adress";
   string Subject = "Test";
   string Body = "Test";   

   // create the email message
   MailMessage completeMessage = new MailMessage(From, To, Subject, Body);
   

   // create smtp client at mail server location
   SmtpClient client = new SmtpClient("my exchange server");

   // add credentials and SSL
   client.UseDefaultCredentials = true;
   client.EnableSsl = true;
   client.DeliveryMethod = SmtpDeliveryMethod.Network;
   

   try
   {
    // send message
    client.Send(completeMessage);
   }
   catch (Exception)
   {
    throw;
   
}


这篇关于通过C#发送电子邮件无法正常工作。目标机器主动拒绝连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆