Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2012, 07:38 AM   PM User | #1
puneet_pr
New to the CF scene

 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
puneet_pr is an unknown quantity at this point
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..
puneet_pr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:35 AM.


Advertisement
Log in to turn off these ads.