Google SMTP无法在服务器上托管网站

时间:2014-02-27 14:30:45

标签: c# iis smtp webserver smtpclient

我有以下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 list 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.Service.ConnectSocketInternal的System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)上主动拒绝它173.194.66.109:587 (Boolean connectFailure,Socket s4,Socket s6,Socket& socket,IPAddress& address,ConnectSocketState state,IAsyncResult asyncResult,Exception& exception)---内部异常堆栈跟踪结束---在System.Net.ServicePoint.GetConnection(PooledStream) System.Net.ConnectionPool.GetConnection(对象拥有对象,System.Net.PooledStream.Activate(Object owningObject,Boolean async,GeneralAsyncDelegate asyncCallback)中的PooledStream,Object owner,Boolean async,IPAddress& address,Socket& abortSocket,Socket& abortSocket6) System.Net.Mail.SmtpClient.Send(Ma)上System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)的GeneralAsyncDelegate asyncCallback,Int32 creationTimeout) ilMessage消息)

0 个答案:

没有答案