Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    email function shows error

    i have 1 application which is developed in ASP.net. my email function working fine 2 day ago. but now it shows an error.http://www.tractebelindia.com/User_List.aspx.pdf.

    please give me solution.

    ---------and User_List.aspx code is --------------
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Net;
    using System.Configuration;
    using System.Net.Mail;
    
    public partial class Admin_User_List : System.Web.UI.Page
    {
        UserADO ComObj;
        DataSet ds;
        DataView dv;
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if ((string)Session["MyTheme"] == null)
            {
                this.Page.Theme = "Kamlesh";
            }
            else
            {
                this.Page.Theme = Session["MyTheme"].ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["_SortExp_"] = null;
                ViewState["_Direction_"] = "ASC";
                sb_Fill_UserData();
            }
        }
    
        private void sb_Fill_UserData()
        {
            try
            {
                ComObj = new UserADO();
                ds = new DataSet();
                string strQry = @"SELECT M_User.UserID, M_User.UserName,M_User.Email, M_User.First_Name, M_User.Last_Name, M_User.User_PWD, M_User.Mobile, M_User.Emp_Code, M_User.DOB, M_User.DOJ,M_User.UserTypeID
                    FROM M_User INNER JOIN M_UserType ON M_User.UserTypeID = M_UserType.UserTypeID order by M_User.UserID ";
                ds = ComObj.Get_DataSet(strQry);
    
                if (ViewState["_SortExp_"] != null)
                {
                    dv = new DataView(ds.Tables[0]);
                    dv.Sort = (string)ViewState["_SortExp_"] + " " + (string)ViewState["_Direction_"];
                }
                else { dv = ds.Tables[0].DefaultView; }
    
                gv_EmployList.DataSource = dv;
                gv_EmployList.DataBind();
            }
            catch (Exception ex) { lblErrMsg.Text = "<img src='../images/err.gif' style='vertical-align:top;'/>" + ex.Message + "</font"; }
            finally { ComObj = null; }
        }
    
    
        protected void gv_EmployList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            
        }
    
        protected void gv_EmployList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int Id = Convert.ToInt32(e.CommandArgument.ToString());
                try
                {
                    string strQry = "delete from M_User where UserID=" + Id + " ";
    
                    ComObj = new UserADO();
                    int lcReturn = ComObj.ExecuteNonQuery_by_Query(strQry);
                    sb_Fill_UserData();
    
                }
                catch (Exception ex) { lblErrMsg.Text = "<img src='../images/err.gif' style='vertical-align:top;'/> " + ex.Message; }
                finally { ComObj = null; }
            }
            if (e.CommandName == "password")
            {
                string[] str = e.CommandArgument.ToString().Split(',');
                string str1, str2;
                str1 = str[0];
                str2 = str[1];
                SendMail(str2,str1);
            }
        }
    
        protected void gv_EmployList_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (ViewState["_Direction_"].ToString() == "ASC")
            {
                ViewState["_Direction_"] = "DESC";
            }
            else if (ViewState["_Direction_"].ToString() == "DESC")
            {
                ViewState["_Direction_"] = "ASC";
                e.SortDirection = SortDirection.Ascending;
            }
    
            ViewState["_SortExp_"] = e.SortExpression;
            string cv = ViewState["_Direction_"].ToString();
            sb_Fill_UserData();
        }
        protected void gv_EmployList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gv_EmployList.PageIndex = e.NewPageIndex;
            sb_Fill_UserData();
        }
        protected void SendMail(string strEmail, string Password)
        {
    
            MailMessage Msg = new MailMessage();
            // Sender e-mail address.
            Msg.From = new MailAddress("dialhr2011@gmail.com", "HR HelpDesk");
            // Recipient e-mail address.
            Msg.To.Add(strEmail);
            Msg.Subject = "HR Helpdesk: Forget Password";
            Msg.Body = "Your Password is " + Password ;
            // your remote SMTP server IP.
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 25;
            smtp.Credentials = new System.Net.NetworkCredential("dialhr2011@gmail.com", "willpower7");
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            lblErrMsg.ForeColor = System.Drawing.Color.Green;
           
            lblErrMsg.Text = "Mail Sent Successfully";
          
            //MailMessage msg = new MailMessage();
            //MailAddressCollection receipents = new MailAddressCollection();
            //string mailreceipent = strEmail;
            //string mailFrom = ConfigurationManager.AppSettings["EmailID"];
            //receipents.Add(mailreceipent);
            //msg.From = new MailAddress(mailFrom);
            //msg.To.Add(receipents.ToString());
            //msg.Subject = "HR Helpdesk: Forget Password";
            //string str = "Your Password is " + Password;
    
            //try
            //{
            //    SmtpClient client = new SmtpClient("relay-hosting.secureserver.net", 25);
            //    client.UseDefaultCredentials = false;
            //    client.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["EmailID"].ToString(), ConfigurationManager.AppSettings["EmailPassword"].ToString());
            //    client.DeliveryMethod = SmtpDeliveryMethod.Network;
            //    client.Send(msg);
            //}
            //catch { }
        }
    }
    Last edited by puneet_pr; 10-19-2012 at 07:44 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •