发送邮件失败:Gmail:如何解决? [英] Failure sending mail : Gmail : How to solve this ?

查看:273
本文介绍了发送邮件失败:Gmail:如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了这段代码,我提到下面的错误请帮我解决这个问题。 :

Hi ,
I used this code, and i mention below error pls help me how to fix this . :

try
{
    MailMessage mail = new MailMessage();
    mail.Subject = txtSubject.Text ;
    mail.From = new MailAddress("Sender@gmail.com");
    mail.To.Add(txtTo.Text.Trim());
    mail.Body = txtBody.Text;
    mail.IsBodyHtml = true;

    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.EnableSsl = true;
    NetworkCredential netCre = new NetworkCredential("Sender@gmail.com", "******");
    smtp.Credentials = netCre;

   if (lblAttachment.Text != "")
    {
        Attachment att = new Attachment(lblAttachment.Text);
        mail.Attachments.Add(att);
    }
    smtp.Send(mail);
    MessageBox.Show("Mail Sended successfully !");



我收到此错误:如何解决此错误:




I am getting this Error : How to solve this Error :

Failure sending mail


See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 74.125.25.109:587
   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, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
   at System.Net.PooledStream.Activate(Object owningObject, Boolean async, 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)
   --- End of inner exception stack trace ---
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at MailSend.Form1.button1_Click(Object sender, EventArgs e)
   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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MailSend
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/MailSend.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17379 built by: FXBETAREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:
<pre lang="HTML">
<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>
<pre lang="xml"></pre>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



HI谢谢


HI thank you

推荐答案

错误已尝试以其访问权限禁止的方式访问套接字您需要与smtp管理员联系以解决此问题。你的代码看起来不错。因此,它可能会被阻止发送给您,或者您的帐户可能存在gmail问题。
The error has "An attempt was made to access a socket in a way forbidden by its access permissions" You'll need to get with your smtp admin to fix this. Your code looks OK. So, it may be blocked to send on your side or it may be your account has issues with gmail.


如果防火墙或防病毒软件阻止该端口,则会出现此问题。



当您使用端口587时,请检查此端口是否被阻止。您可以关闭防火墙和防病毒软件以测试邮件发送。如果它工作,那就是问题。



如果你想启用防火墙,那么按照描述在哪里 [ ^ ]
This issue comes if the Firewall or Antivirus blocks the port.

As you are using port 587, so check if this port is blocked or not. You can off the Firewall and Antivirus to test the mail sending. If it works, then that is the issue.

If you want to have Firewall on, then add one Exception to Firewall as described here[^]






试试这种方法,



http://www.serversmtp.com/en/smtp-for-windows-7 [ ^ ]


这篇关于发送邮件失败:Gmail:如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆