1

我正在使用 Visual Studio 2012 RC 中的 .net 框架 4.5 在 C# 中构建应用程序。

为了申请反馈和问题,我正在向我的帐户发送电子邮件。这是一个小应用程序。

几天前,我的应用程序运行良好。我正在接收电子邮件。

现在我收到异常弹出“发送邮件失败”。

我尝试了很多调整,但没有效果。我的帐户没有要求重新激活。我也关闭了我的防火墙.. 没有任何工作同样的例外。我附上了一个例外细节。也。请看一下。

请帮我。我做了太多的谷歌。

我的代码是

MailMessage message = new MailMessage();
try
{
    message.To.Add(new MailAddress(mailTo));
    message.From = new MailAddress(mailFrom);

    //Attachment attachment = new Attachment(FileUpload1.PostedFile.FileName);
    message.Subject = "McFarlane Industries Product's Registration Request";
    message.Body = packageRequestContent();
    message.BodyEncoding = System.Text.Encoding.UTF8;
    message.SubjectEncoding = System.Text.Encoding.UTF8;
    //message.Attachments.Add(attachment);


    SmtpClient client = new SmtpClient();
    client.Port = 587; // Gmail works on this port
    client.Host = "smtp.gmail.com";
    System.Net.NetworkCredential nc = new System.Net.NetworkCredential(mailFrom, mailFromPass);
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = nc;
    client.Send(message);
    MessageBox.Show("Thank you for Registring...!", "Register Notification!", MessageBoxButtons.OK, MessageBoxIcon.Information);


}
catch (Exception ex)
{
    MessageBox.Show("Request not submitted. " + ex.Message);
}

异常详情如下:

System.Net.Mail.SmtpException was unhandled
  HResult=-2146233088
  Message=Failure sending mail.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at McFarlaneIndustriesPOSnamespace.Registration.sendMailUsingHotmail(String mailFrom, String mailFromPass, String mailTo) in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\Registration.cs:line 73
       at McFarlaneIndustriesPOSnamespace.Registration.buttonSendRegistrationRequest_Click(Object sender, EventArgs e) in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\Registration.cs:line 47
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at McFarlaneIndustriesPOSnamespace.Program.Main() in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\Program.cs:line 20
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.IOException
       HResult=-2146232800
       Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
            at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
            at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
            at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
            at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)
            at System.Net.Mail.StartTlsCommand.Send(SmtpConnection conn)
            at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: System.Net.Sockets.SocketException
            HResult=-2147467259
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            InnerException:
4

1 回答 1

1

我会尝试使用网络界面登录 Hotmail/Gmail 帐户。有时Hotmail会随机锁定你的账户,让你重设密码;特别是如果您使用该帐户发送批量电子邮件。

于 2012-07-03T03:38:04.677 回答