locked
Problems Sending Emails

    Question

  • I've tried sending an email with this code

                    mail.From = new MailAddress("address@hotmail.com");
                    mail.To.Add("address@hotmail.com");
                    mail.Subject = "Error Message/OMS Visual Editor";
                    mail.Body = "The following user:" + System.Environment.MachineName + "Has sent you an error message.\n" + this.richTextBox1.Text;
                    mail.Priority = MailPriority.High;
                    // Sends the email.
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("192.168.1.66");
                    smtp.Send(mail);
    But there was a problem sending the email. Any ideas on what I might have did wrong, even if it's a minor detail(s) i might have missed.
    Thursday, December 03, 2009 11:36 AM

Answers

  • WSAEACCES
    10013

    Permission denied.

    An attempt was made to access a socket in a way forbidden by its access permissions. An example is using a broadcast address for sendto without broadcast permission being set using setsockopt (SO_BROADCAST).

    Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4.0 with SP4 and later), another application, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.

    • Marked as answer by Harry Zhu Monday, December 14, 2009 7:06 AM
    Monday, December 07, 2009 1:19 PM
  • Developer911,

    This could be a network problem. Maybe a firewall that is blocking your request. Have you check this?

    Best regards.

    Ari C. Raimundo
    • Marked as answer by Harry Zhu Monday, December 14, 2009 7:06 AM
    Monday, December 07, 2009 12:24 PM

All replies

  • Developer911,

    Can you post the error?

    Best regards.

    Ari C. Raimundo
    Thursday, December 03, 2009 12:05 PM
  • the problem was in the smtp.send(mail) command, when i triggered it.
    Thursday, December 03, 2009 10:39 PM
  • Developer911,

    What kind of exception the code throws? Can you post the stack trace here?

    Best regards.

    Ari C. Raimundo
    Friday, December 04, 2009 12:48 AM
  • Developer911,

    Strange error. Your code has specified from address but the exception cause is that from address wasn't specified.
    Did the from address is a valid mail address in your SMTP server?

    Best regards.

    Ari C. Raimundo
    Saturday, December 05, 2009 11:49 PM
  • Oops sent posted the wrong error this is the more up to date exception.

    System.Net.Mail.SmtpException was unhandled
      Message="Failure sending mail."
      Source="System"
      StackTrace:
           at System.Net.Mail.SmtpClient.Send(MailMessage message)
           at OMS_Visual_Editor.Error_Report.send_Bttn_Click(Object sender, EventArgs e) in C:\Users\Nick\Documents\Visual Studio 2008\Projects\OMS Visual Editor\OMS Visual Editor\Error Report.cs:line 66
           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(Int32 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.RunDialog(Form form)
           at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
           at System.Windows.Forms.Form.ShowDialog()
           at OMS_Visual_Editor.OMS_Visual_Editor.reportErrorToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\Nick\Documents\Visual Studio 2008\Projects\OMS Visual Editor\OMS Visual Editor\OMS Visual Editor.cs:line 141
           at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
           at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
           at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ToolStrip.WndProc(Message& m)
           at System.Windows.Forms.ToolStripDropDown.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(Int32 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 OMS_Visual_Editor.Program.Main() in C:\Users\Nick\Documents\Visual Studio 2008\Projects\OMS Visual Editor\OMS Visual Editor\Program.cs:line 18
           at System.AppDomain._nExecuteAssembly(Assembly 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)
           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(String host, Int32 port)
                at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
                at System.Net.Mail.SmtpClient.GetConnection()
                at System.Net.Mail.SmtpClient.Send(MailMessage message)
           InnerException: System.Net.Sockets.SocketException
                Message="An attempt was made to access a socket in a way forbidden by its access permissions 192.168.1.66:25"
                Source="System"
                ErrorCode=10013
                NativeErrorCode=10013
                StackTrace:
                     at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                     at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
                     at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
                InnerException:
    Sunday, December 06, 2009 1:18 AM
  • Developer911,

    Did your SMTP server requires authentication? Please see link below:

    SmtpClient.Credentials Property
    http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.aspx

    Ari C. Raimundo
    Sunday, December 06, 2009 1:50 AM
  • I wouldnt believe so.
    Sunday, December 06, 2009 2:07 AM
  • Developer911,

    This could be a network problem. Maybe a firewall that is blocking your request. Have you check this?

    Best regards.

    Ari C. Raimundo
    • Marked as answer by Harry Zhu Monday, December 14, 2009 7:06 AM
    Monday, December 07, 2009 12:24 PM
  • WSAEACCES
    10013

    Permission denied.

    An attempt was made to access a socket in a way forbidden by its access permissions. An example is using a broadcast address for sendto without broadcast permission being set using setsockopt (SO_BROADCAST).

    Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4.0 with SP4 and later), another application, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.

    • Marked as answer by Harry Zhu Monday, December 14, 2009 7:06 AM
    Monday, December 07, 2009 1:19 PM
  • Hi,

    Does the suggestion from Ari C.Raimundo and JediJohn82 work for you?

    Harry

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, December 10, 2009 2:45 AM