Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Google SMTP无法在服务器上托管站点_C#_Iis_Smtp_Webserver_Smtpclient - Fatal编程技术网

C# Google SMTP无法在服务器上托管站点

C# Google SMTP无法在服务器上托管站点,c#,iis,smtp,webserver,smtpclient,C#,Iis,Smtp,Webserver,Smtpclient,我有下面的C#代码从web应用程序发送邮件,但它可以工作并仅在visual studio中本地运行时发送邮件,而在我将网站托管到服务器时它不会发送邮件。代码如下: var fromAddress = ConfigurationManager.AppSettings["fromAddress"]; var toAddress = ConfigurationManager.AppSettings["toAddress"]; string fromPassword = ConfigurationMa

我有下面的C#代码从web应用程序发送邮件,但它可以工作并仅在visual studio中本地运行时发送邮件,而在我将网站托管到服务器时它不会发送邮件。代码如下:

var fromAddress = ConfigurationManager.AppSettings["fromAddress"];
var toAddress = ConfigurationManager.AppSettings["toAddress"];

string fromPassword = ConfigurationManager.AppSettings["fromPassword"];

MailMessage msg= new MailMessage();
SmtpClient smtp = new SmtpClient();
try
{
  msg.To.Add(toAddress);
  msg.Body = "From: " + TextBox2.Text + "\n"
    + "Name: " + TextBox1.Text + "\n"
      + "Message: " + TextBox3.Text + "\n";
  msg.Subject = "Aztech Website Contact Form";
  msg.From = new MailAddress(toAddress);

  smtp.Host = "smtp.gmail.com";
  smtp.Port = 587;
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
  smtp.Timeout = 300000;
  smtp.Send(msg);
  Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "showAlert();", true);
}
catch (Exception ex)
{
  Label1.Text = ex.Message;
  Label1.Visible = true;
}
请建议如何在将此邮件功能托管到服务器后使其在web应用程序上工作。服务器中的IIS管理器是否需要进行任何更改

输出

appcmd列表apppool“new.aztech.ie”/text:*

详情如下:

   C:\Windows\System32\inetsrv> appcmd list apppool "new.aztech.ie" /text:*
APPPOOL
  APPPOOL.NAME:"new.aztech.ie"
  PipelineMode:"Integrated"
  RuntimeVersion:"v4.0"
  state:"Started"
  [add]
    name:"new.aztech.ie"
    queueLength:"1000"
    autoStart:"true"
    enable32BitAppOnWin64:"false"
    managedRuntimeVersion:"v4.0"
    managedRuntimeLoader:"webengine4.dll"
    enableConfigurationOverride:"true"
    managedPipelineMode:"Integrated"
    CLRConfigFile:""
    passAnonymousToken:"true"
    startMode:"OnDemand"
    [processModel]
      identityType:"ApplicationPoolIdentity"
      userName:""
      password:""
      loadUserProfile:"false"
      setProfileEnvironment:"true"
      logonType:"LogonBatch"
      manualGroupMembership:"false"
      idleTimeout:"00:20:00"
      maxProcesses:"1"
      shutdownTimeLimit:"00:01:30"
      startupTimeLimit:"00:01:30"
      pingingEnabled:"true"
      pingInterval:"00:00:30"
      pingResponseTime:"00:01:30"
    [recycling]
      disallowOverlappingRotation:"false"
      disallowRotationOnConfigChange:"false"
      logEventOnRecycle:"Time, Memory, PrivateMemory"
      [periodicRestart]
        memory:"0"
        privateMemory:"0"
        requests:"0"
        time:"1.05:00:00"
        [schedule]
    [failure]
      loadBalancerCapabilities:"HttpLevel"
      orphanWorkerProcess:"false"
      orphanActionExe:""
      orphanActionParams:""
      rapidFailProtection:"true"
      rapidFailProtectionInterval:"00:05:00"
      rapidFailProtectionMaxCrashes:"5"
      autoShutdownExe:""
      autoShutdownParams:""
    [cpu]
      limit:"0"
      action:"NoAction"
      resetInterval:"00:05:00"
      smpAffinitized:"false"
      smpProcessorAffinityMask:"4294967295"
      smpProcessorAffinityMask2:"4294967295"
内部异常:


System.Net.WebException:无法连接到远程服务器--->System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在System.Net.ServicePoint.ConnectSocketInternal的System.Net.Sockets.Socket.DoConnect(EndPoint EndPoint endPointSnapshot,SocketAddress SocketAddress)上主动拒绝了它173.194.66.109:587(布尔连接失败、套接字s4、套接字s6、套接字和套接字、IPAddress和address、ConnectSocketState状态、IAsyncResult asyncResult、异常和异常)----内部异常堆栈跟踪的结束---位于System.Net.ServicePoint.GetConnection(PooledStream PooledStream、对象所有者、布尔异步、IPAddress&address、Socket&abortSocket、Socket&abortSocket6)在System.Net.PooledStream.Activate(Object owningObject、Boolean async、GeneralAsyncDelegate asyncCallback)在System.Net.ConnectionPool.GetConnection(Object owningObject、GeneralAsyncDelegate asyncCallback、Int32 creationTimeout)位于System.Net.Mail.SmtpConnection.GetConnection(ServicePoint ServicePoint)处的System.Net.Mail.SmtpClient.Send(MailMessage)处的

是的,我做了更改并允许使用端口587,但邮件仍然没有发送。没有引发任何异常。上述代码中使用的凭据是gmail凭据。我已编辑了问题以显示命令的输出。您可以从Web服务器执行tracert smtp.gmail.com以查看使用了哪些路由器和交换机。其中一个框在您的网络段中,您正在阻止端口587上的通信