Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
i have error message (Failure sending mail)

in public class i have this code to send message:
C#
public static bool sendMail(string subject, string msg, string to)
{
    MailMessage mmsg = new MailMessage("wolf@gmail.com", to, subject, msg);
    mmsg.IsBodyHtml = true;

    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
    client.UseDefaultCredentials = false;
    NetworkCredential cre = new NetworkCredential("wolf1@gmail.com", "yourPass");
    client.Credentials = cre;
    client.EnableSsl = true;

    try
    {
        client.Send(mmsg);
        return true;
    }
    catch
    {
        return false;
    }
}


in another class i have a method

in my class called member i have two methods

C#
private void initialize(CommandType CT,string DBcall)
{
    conn = new SqlConnection();
    cmd = new SqlCommand();

    //requirement
    conn.ConnectionString = ConfigurationManager.ConnectionStrings[1].ToString();
    cmd.Connection = conn;
    cmd.CommandType =CT ;
    cmd.CommandText = DBcall;
    conn.Open(); 
}

public DataTable runQuery(string select)
{
  initialize(CommandType.Text, select);
  tbl = new DataTable();
  tbl.Load(cmd.ExecuteReader());
  conn.Close();
  return tbl;
}

in class call member i have method :
C#
public string getEmail(string userName)
{
    try
    {
        return dbVar.runQuery("select email from members where userName= '" + userName + "' ").Rows[0][0].ToString();
    }
    catch
    {
        return "";
    }


}

In may page i have wizard control when i double click in it i call above class code
C#
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
    member m=new member();

   if (utility.sendMail("leader order ", lblMessage.Text, m.getEmail(c.UserName)))
       lblMessage.Text += "email sent to conformation ,to your email ";
   else
       lblMessage.Text += "email not sent :" + m.getEmail(c.UserName);
Posted
v4
Comments
[no name] 21-Aug-13 7:50am    
And the exception is what?
ZurdoDev 21-Aug-13 8:00am    
Give the specific error.
ali_heidari_ 21-Aug-13 8:08am    
catch(exception ex){
// show exception detail
}
here you can find more exception class to get more details
http://msdn.microsoft.com/en-us/library/swas0fwc.aspx
Anele Ngqandu 21-Aug-13 8:17am    
Hi, had the same problem few days back. I sent the email to my gmail account and it was blocked by google mail for security reasons. They sent me a message asking me to confirm that I was the one trying to access my account.

So are you sending the email to yourself?
CodeBlack 21-Aug-13 8:20am    
can you improve your question with exception details ?

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