Click here to Skip to main content
15,312,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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("iyalarasi.r@winxsolutions.com"));
        mm.From = new System.Net.Mail.MailAddress("iyalarasi.r@winxsolutions.com");
        mm.Sender = new System.Net.Mail.MailAddress("iyalarasi.r@winxsolutions.com");
        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();
        }
    }


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.
Posted
Updated 17-Oct-12 2:23am
v2

1 solution

I Think u use this code its not work locally its worked while its Online

just check it out

XML
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 = "info@TestMail.co.in";
        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);
    }
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900