2012-07-26 2 views
0

데이터베이스를 쿼리하고 보고서를 내보내고 상태를 전자 메일로 보내는 프로그램을 만들려고합니다. 전자 메일 부분에 붙어 있습니다. 나는 계속 "메일을 보내지 못했습니다."및 smtpException이 처리되지 않았습니다. "나는 이것을 수행하는 회사가 네트워크 프록시를 가지고 있기 때문에 인터넷에 액세스 할 수 있습니다. 이메일을 보낼 수 없습니다. 필요한 것이 있습니까? 이 프록시를 통해 보낼 수 있도록 추가 여기에 오류가 : 여기네트워크 프록시를 통해 C#을 사용하여 전자 메일 보내기

MailMessage message = new MailMessage(); 

    message.To.Add(new MailAddress("[email protected]")); 
    message.From = new MailAddress("[email protected]"); 
    //Attachment attachment = new Attachment(FileUpload1.PostedFile.FileName); 
    message.Subject = "Subject"; 
    message.Body = "This is a test"; 

    //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("[email protected]", "pass"); 
    client.EnableSsl = true;  
    client.UseDefaultCredentials = false; 
    client.Credentials = nc; 
    client.Send(message); 

(가) 포함되어 있습니다 : 여기

System.Net.Mail.SmtpException was unhandled 
    Message=Failure sending mail. 
    Source=System 
    StackTrace: 
     at System.Net.Mail.SmtpClient.Send(MailMessage message) 
     at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\DavidPaquette\My Documents\Visual Studio 2010\Projects\TestMail\TestMail\Form1.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 WindowsFormsApplication1.Program.Main() in C:\Documents and Settings\DavidPaquette\my documents\visual studio 2010\Projects\TestMail\TestMail\Program.cs:line 18 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.Net.WebException 
     Message=Unable to connect to the remote server 
     Source=System 
     StackTrace: 
      at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) 
      at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) 
      at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) 
      at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) 
      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 
      Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.194.70.108:587 
      Source=System 
      ErrorCode=10060 
      NativeErrorCode=10060 
      StackTrace: 
       at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 
       at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) 
      InnerException: 

그리고 것은 코드의 이메일 부분이다

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.IO; 
using System.Windows.Forms; 
using System.Net; 
using System.Collections; 
using System.Text.RegularExpressions; 
using System.Net.Mail; 

답변

1

당신은 추가하지 않는 한 http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx이 추가하고 (SMTP 서버에 대한) 모든 발신 전화를 구성한 후에

<configuration> 
    <system.net> 
    <defaultProxy> 
     <proxy 
     usesystemdefault="true" 
     proxyaddress="http://192.168.1.10:3128" 
     bypassonlocal="true" 
     /> 
     <bypasslist 
     <add address="[a-z]+\.contoso\.com" /> 
     </bypasslist> 
    </defaultProxy> 
    </system.net> 
</configuration> 

이 (프록시 서버를 통해 갈 것입니다, 당신의 web.config 파일에 프록시 서버를 추가 할 수 있습니다 그것은 우회 목록에 ...).

/빅토르

+0

'SmtpClient'코드에서 어떻게 구성합니까? – JobaDiniz

관련 문제