本文介绍了发送邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的asp.net Web应用程序发送一封邮件,这里我使用发往和发往该地址的邮件进行测试
我使用的是webmail.1and1.com.

我的系统中没有gmail,并且还没有配置smtp,
因此以下代码不起作用

I want to send a mail from my asp.net web application,here I am using same from and to address,for testing
I am using webmail.1and1.com for my outlook.

I am not having gmail in my system,and smtp also is not configured,
so the following code is not work

protected void btnsubmit_Click(object sender, EventArgs e)
    {
        Response.Write("you have applied" + ddl.SelectedItem.ToString());

        System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
        mm.To.Add(new System.Net.Mail.MailAddress("[email protected]"));
        mm.From = new System.Net.Mail.MailAddress("[email protected]");
        mm.Sender = new System.Net.Mail.MailAddress("[email protected]");
        mm.Subject = "Request for Leave";
        mm.Body = txteno .Text+"request"+ddl.SelectedItem .ToString ()+"leave";
        mm.IsBodyHtml = true;
        mm.Priority = System.Net.Mail.MailPriority.High; // Set Priority to sending mail
        System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
        smtCliend.Host = "pop.1and1.com";
        smtCliend.Port = 25;    // smtp port no            
        smtCliend.Credentials = new NetworkCredential("User Name", "Password");
        smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        try
        {
            smtCliend.Send(mm);
        }
        catch (System.Net.Mail.SmtpException ex)
        {
            lblmsg.Text = ex.ToString();
        }
        catch (Exception exe)
        {
            lblmsg.Text = "\n\n\n" + exe.ToString();
        }
    }



错误显示为,
System.Net.Mail.SmtpException:发送邮件失败. ---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在System.Net.Sockets.Socket上主动拒绝了System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)上的74.208.5.5:25 System.Net.ServicePoint.ConnectSocketInternal上的.InternalConnect(EndPoint remoteEP)(布尔值connectFailure,Socket s4,Socket s6,Socket&套接字,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,Exception&异常)内部异常堆栈跟踪---在System.Net.PooledStream.Activate(Object System.Net.PooledStream.Activate处的owningObject,布尔异步,Int32超时,GeneralAsyncDelegate asyncCallback)(System.Net.ConnectionPool.GetConnec处的ObjectowningObject,GeneralAsyncDelegate asyncCallback) System.Net.Mail.SmtpConnection.GetConnection(字符串主机,Int32端口)处的System.Net.Mail.SmtpTransport.GetConnection(字符串主机,Int32端口)处的tion(对象owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout). System.Net.Mail.SmtpClient.Send(MailMessage消息)处的Mail.SmtpClient.GetConnection()---内部异常堆栈跟踪的末尾--- System.Net.Mail.SmtpClient.Send(MailMessage消息)处的_Default. dn:\ 15 \ WebLeave \ Default.aspx.cs:line 37中的btnsubmit_Click(Object sender,EventArgs e)



给我一些如何使用webmail.1and1.com发送电子邮件的链接

请尽快帮助我.

在此先感谢您.



It shows the error as,
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 74.208.5.5:25 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) --- End of inner exception stack trace --- 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) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.btnsubmit_Click(Object sender, EventArgs e) in d:\15\WebLeave\Default.aspx.cs:line 37



give me some links that how to send an email using webmail.1and1.com

Please help me soon.

Thanks in advance.

推荐答案

protected void SendMail()
    {
        MailMessage MyMsg = new MailMessage();
        SmtpClient MySmtp = new SmtpClient();
        string StrTo, StrFrom, StrSubject, StrBody;

        StrSubject = "Discover: " + txtName.Text.ToString();
        StrBody = "From: " + txtName.Text + "</ br>";
        StrBody += "Institute Name : " + txtInstitute.Text + "</ br>";
        StrBody += "Mobile No : " + txtMobileNo.Text + "</ br>";
        StrBody += "Phone No : " + txtPhoneNo.Text + "</ br>";
        StrBody += "E-Mail Address : " + txtEMail.Text + "</ br>";
        StrBody += "WebSite : " + txtWebsite.Text + "</ br>";
        StrBody += "State : " + ddlState.SelectedItem.ToString() + "</ br>";
        StrBody += "District : " + ddlDistricts.SelectedItem.ToString() + "</ br>";
        StrBody += "City : " + ddlCity.SelectedItem.ToString() + "</ br>";
        StrBody += "Area : " + ddlArea.SelectedItem.ToString() + "</ br>";
        StrBody += "Address : " + txtAddress.Text + "</ br>";
        StrBody += "Intrested In : " + ddlIntrested.SelectedItem.ToString() + "</ br>";
        StrBody += "Comments : " + txtComments.Text + "</ br>";

        // smtp settings
        StrTo = "[email protected]";
        StrFrom = txtEMail.Text;
        StrBody = MailBody();
        MyMsg = new MailMessage(StrFrom, StrTo, StrSubject, StrBody);
        MyMsg.IsBodyHtml = true;
        MySmtp = new SmtpClient("localhost");
        MySmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        MySmtp.Send(MyMsg);
    }


这篇关于发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:12