Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i want to send a mail from asp.net application
i have take the following control in asp.net application

XML
<form id="form1" runat="server">
   <div>

       <table class="style1">
           <tr>
               <td>
                   To</td>
               <td>
                   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   From</td>
               <td>
                   <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   Password</td>
               <td>
                   <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   CPassword<
               <td>
                   <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   Subject</td>
               <td>
                   <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   Body</td>
               <td>
                   <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
               </td>
           </tr>
           <tr>
               <td>
                   File</td>
               <td>
                   <asp:FileUpload ID="FileUpload1" runat="server" />
               </td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   &nbsp;</td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
                       Text="Send Email" />
               </td>
           </tr>
           <tr>
               <td>
                   &nbsp;</td>
               <td>
                   <asp:Label ID="Label1" runat="server"></asp:Label>
               </td>
           </tr>
       </table>
       
   </div>
   </form>


then i have add the following coding in send Email button

C#
using System.Net.Mail;
using System.IO;

{
 MailMessage mail = new MailMessage();
        mail.To.Add(TextBox1.Text.ToString());
        mail.From = new System.Net.Mail.MailAddress(TextBox2.Text.ToString());
        mail.Subject = TextBox3.Text.ToString();
        mail.Body = TextBox4.Text.ToString();
        if (FileUpload1.HasFile)
        {
            mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
        }
        SmtpClient smp = new SmtpClient("Smtp.gmail.com");
        smp.Credentials = new System.Net.NetworkCredential(TextBox2.Text.ToString(), TextBox3.Text.ToString());
        smp.Port = 589;
        smp.Host = "smtp.gmail.com";
        smp.EnableSsl = true;
        smp.Send(mail);
        Label1.Text = "Send message Succesfully";
    }

when run this application it can and i pass the following information on following textboxes when i click the send email button the follwing error will occur


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 74.125.53.109:589

Exception Details: System.Net.Sockets.SocketException: 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 74.125.53.109:589




so please help me i cant understand the exact error
Posted
Updated 27-Dec-11 21:38pm
v2

I think you have not send the port number in your SMTP constructor
check the following code
C#
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587); // add port 587
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);
 
Share this answer
 
use this code to send mail from smtp (Gmail)
MailMessage oMsg = new MailMessage();
                oMsg.From = new MailAddress("securuslistner@gmail.com", "Securus Listner");
                oMsg.To.Add(new MailAddress("rajeshcragy@gmail.com", "Securus Listner"));
                oMsg.Subject = "Packet Parsing Problem";
                oMsg.Body = " Problem Occuread test mail";
                oMsg.SubjectEncoding = System.Text.Encoding.UTF8;
                oMsg.BodyEncoding = System.Text.Encoding.UTF8;
                oMsg.IsBodyHtml = false;
                oMsg.Priority = MailPriority.High;
 
                SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 587);
                oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                oSmtp.EnableSsl = true;
 
                NetworkCredential oCredential = new NetworkCredential("securuslistner@gmail.com", "<password>");
                oSmtp.UseDefaultCredentials = false;
                oSmtp.Credentials = oCredential;
                oSmtp.Send(oMsg);
 
Share this answer
 
Hi,

You may see this link for further exception detail..
VB
Gmail as a free smtp server



Regards,
 
Share this answer
 

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