Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created one web form page, in that i have 2 buttons "approve" and "reject", after clicking on button, mail has sent to user.

My question is, if i want to put 2 image or button named as "approve" and "reject" in email body, And on click event of that button or image, i want to send the request again for click event of the button of web page that i have created first.
I put my form behind code below, please help me to get write code...

C#
protected void lnbtn_Approve_Click(object sender, EventArgs e)
{
    LinkButton lnkbtn = sender as LinkButton;
    //getting particular row linkbutton
    GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
    //getting userid of particular row
    int Id = Convert.ToInt32(GV_LatLongApproval.DataKeys[gvrow.RowIndex].Value.ToString());
    DropDownList DDL = (DropDownList)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("drp_Closeby");
    Label Project = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Project");
    Label NewLat = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Userlat");
    Label NewLong = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Userlong");
    Label OldLat = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitelat");
    Label OldLong = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitelong");
    Label Username = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Username");
    Label Siteid = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Siteid");
    Label Sitename = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitename");
    Label OTime = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Requestedtime");
    Label Distance = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Distance");
    Label Circle = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Circle");
    Label MCompany = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_MCompany");
    Label SCompany = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_SCompany");
    Label Mobile = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Mobile");
    Label Zone = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Zone");

    if (DDL.SelectedValue.ToString() != "0")
    {
        string CloseBy = DDL.SelectedItem.Text;
        DA = new FindDataAccess();
        DataTable SiteDT = new DataTable();
        SiteDT = DA.SELECT_ID_SITEID(Siteid.Text);
        DA = new FindDataAccess();
        DA.select_update_lat_long_su(float.Parse(NewLat.Text), float.Parse(NewLong.Text), Convert.ToInt32(SiteDT.Rows[0]["ID"]), 1, Username.Text);
        DA = new FindDataAccess();
        DataTable DC = new DataTable();
        DC = DA.CLOSE_TT_22042016(Id, CloseBy, "Approve");
        if (DC.Rows.Count > 0)
        {
            if (Convert.ToInt32(DC.Rows[0][0].ToString()) == 1)
            {
                Send_Email_To_User("Approve", Project.Text, Username.Text, Siteid.Text, Sitename.Text, OTime.Text, DateTime.Now.ToString(), OldLat.Text, OldLong.Text, NewLat.Text, NewLong.Text, Distance.Text, Circle.Text, Mobile.Text, MCompany.Text, SCompany.Text, Zone.Text);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + Siteid.Text + " Request already processed.')", true);
            }
        }
        Fill_GV_LatLongApproval();
    }
    else
    {

    }
}

protected void lnbtn_Reject_Click(object sender, EventArgs e)
{
    LinkButton lnkbtn = sender as LinkButton;
    //getting particular row linkbutton
    GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
    //getting userid of particular row
    int Id = Convert.ToInt32(GV_LatLongApproval.DataKeys[gvrow.RowIndex].Value.ToString());
    DropDownList DDL = (DropDownList)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("drp_Closeby");
    Label Project = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Project");
    Label NewLat = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Userlat");
    Label NewLong = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Userlong");
    Label OldLat = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitelat");
    Label OldLong = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitelong");
    Label Username = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Username");
    Label Siteid = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Siteid");
    Label Sitename = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Sitename");
    Label OTime = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Requestedtime");
    Label Distance = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Distance");
    Label Circle = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Circle");
    Label MCompany = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_MCompany");
    Label SCompany = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_SCompany");
    Label Mobile = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Mobile");
    Label Zone = (Label)GV_LatLongApproval.Rows[gvrow.RowIndex].FindControl("lbl_Zone");

    if (DDL.SelectedValue.ToString() != "0")
    {
        string CloseBy = DDL.SelectedItem.Text;
        DA = new FindDataAccess();
        DataTable DC = new DataTable();
        DC = DA.CLOSE_TT_22042016(Id, CloseBy, "Reject");
        if (DC.Rows.Count > 0)
        {
            if (Convert.ToInt32(DC.Rows[0][0].ToString()) == 1)
            {
                // Send_Email_To_User("Approve", Username.Text, Siteid.Text, Sitename.Text, OTime.Text, DateTime.Now.ToString(), OldLat.Text, OldLong.Text, NewLat.Text, NewLong.Text, Distance.Text, Circle.Text, Mobile.Text, MCompany.Text, SCompany.Text);
                Send_Email_To_User("Reject", Project.Text, Username.Text, Siteid.Text, Sitename.Text, OTime.Text, DateTime.Now.ToString(), OldLat.Text, OldLong.Text, NewLat.Text, NewLong.Text, Distance.Text, Circle.Text, Mobile.Text, MCompany.Text, SCompany.Text, Zone.Text);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + Siteid.Text + " Request already processed.')", true);
            }
        }
        Fill_GV_LatLongApproval();
    }
    else
    {

    }
}

protected void Send_Email_To_User(string Action_Status, string ProjectName, string Username, string SiteId, string SiteName, string OTime, string CTime, string OLat, string OLong, string NLat, string NLong, string Distance, string Circle, string Mobile, string MCompnay, string SCompany, string Zone)
{
    try
    {
        mydataaccess2 da2 = new mydataaccess2();
        string to_email = "";
        to_email = da2.get_email_id_user(Username);

        if (to_email != "" && to_email != null)
        {
            // Vodafone SMTP Credentials
            string Body = Email_Body(Action_Status, ProjectName, Username, SiteId, SiteName, OTime, CTime, OLat, OLong, NLat, NLong, Distance, Circle, Mobile, to_email, MCompnay, SCompany, Zone);

            MailMessage message = new MailMessage("citappsupport@vodafone.com", to_email);
            if (Action_Status.ToLower() == "approve")
            {
                message.Subject = "Your Lat-Long Update Request Approved by Helpdesk For Site : " + SiteId;
            }
            else
            {
                message.Subject = "Your Lat-Long Update Request Rejected by Helpdesk For Site : " + SiteId;
            }
            message.Body = Body;
            message.CC.Add("la.helpdesk@gmail.com");
            message.IsBodyHtml = true;

            #region "VODAFONE SERVER CREDENTIALS"

            SmtpClient emailClient = new SmtpClient("10.87.138.252", 254);
            emailClient.Credentials =
                       new NetworkCredential("china@mobile.com", "51561615");

            emailClient.EnableSsl = false;

            #endregion

            #region "CREDENTIALS"

            //SmtpClient emailClient = new SmtpClient("china@mobile.com", 254);
            //emailClient.Credentials = new NetworkCredential("china@mobile.com", "51561615");
            //emailClient.EnableSsl = true;

            #endregion

            emailClient.Send(message);
        }
    }
    catch (Exception ex)
    {

    }
}

public string Email_Body(string Action_Status, string ProjectName, string Username, string SiteId, string SiteName, string OTime, string CTime, string OLat, string OLong, string NLat, string NLong, string Distance, string Circle, string Mobile, string Email, string MCompnay, string SCompany, String Zone)
{
    string Body = "";

    Body = "Dear " + Username + "<br><br>";

    if (Action_Status.ToLower() == "approve")
    {
        Body += "Your Lat / Long Request has been approved. Please refresh Your site selection page and select zone name as per below.<br><br>";

        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "<table border="1"><tbody><tr style="background-color: red; color: white"><th>ProjectName</th><th>Site Id</th> <th>Site Name</th> <th>Zone</th> <th>Requested time by user</th> <th>Approve Time By Support Team</th> <th>Old lat of site</th> <th>Old long of site</th> <th>New lat of site</th> <th>New long of site</th> <th>Distance updated in mtr</th></tr><tr><td>" + ProjectName + "</td><td>" + SiteId + "</td> <td>" + SiteName + "</td> <td>" + Zone + "</td> <td>" + OTime + "</td> <td>" + CTime + "</td> <td>" + OLat + "</td> <td>" + OLong + "</td> <td>" + NLat + "</td> <td>" + NLong + "</td> <td>" + Distance + "</td></tr></tbody></table><br>";
    }
    else
    {
        Body += "Your Lat / Long Request has been Rejected due to Distance from site is more than 2km.<br><br>";
        Body += "If you want to Update lat-long as per your location ,then please take approval of your circle admin on this mail and send mail post approval to CIAT Helpdesk on ciat.ptw@gmail.com.<br>";
        Body += "Do not send this mail without any approval of your circle admin, Lat-long will not update by CIAT Help desk until Approval Given.<br><br>";

        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "";
        Body += "<table border="1"><tbody><tr style="background-color: red; color: white"><th>ProjectName</th><th>Site Id</th> <th>Site Name</th><th>Zone</th> <th>Requested time by user</th> <th>Rejected Time By Support Team</th> <th>Current lat of site</th> <th>Current long of site</th> <th>User lat</th> <th>User long</th> <th>Requested distance to update as per user location in mtr</th></tr><tr><td>" + ProjectName + "</td><td>" + SiteId + "</td> <td>" + SiteName + "</td> <td>" + Zone + "</td> <td>" + OTime + "</td> <td>" + CTime + "</td> <td>" + OLat + "</td> <td>" + OLong + "</td> <td>" + NLat + "</td> <td>" + NLong + "</td> <td>" + Distance + "</td></tr></tbody></table><br>";
    }

    Body += "";
    Body += "";
    Body += "";
    Body += "";
    Body += "";
    Body += "";
    Body += "";
    Body += "<table border="1"><tbody><tr style="background-color: red; color: white"><th>Requested by username</th> <th>Circle</th> <th>Mobile number of user</th> <th>EmailId of user</th> <th>Main company</th> <th>Sub Company</th></tr><tr><td>" + Username + "</td> <td>" + Circle + "</td> <td>" + Mobile + "</td> <td>" + Email + "</td> <td>" + MCompnay + "</td> <td>" + SCompany + "</td></tr></tbody></table><br>";

    Body += "Please Note :- Do not Reply on this mail if you have any query then ,please contact as below.<br><br>";
    Body += "Contact Us :-<br>";
    Body += "Helpdesk Number :- 079 40009543 , 8141587709 , 9978791606, 9727716004<br>";
    Body += "Email :- helpdesk@help.com<br>";

    return Body;
}


What I have tried:

i have searched on internet, but can't get proper information to do this...
Posted
Updated 19-Feb-17 17:31pm
v6
Comments
Karthik_Mahalingam 17-Feb-17 23:08pm    
what about href?

Quote:
how to send request from anyone's mail and from any browser to direct execute the click event of the buttons

On the PageLoad event of the web page. call the button click event directly in which you want to inovke.
 
Share this answer
 
Not your question, but ...
C#
SmtpClient emailClient = new SmtpClient("10.87.138.24", 25);
emailClient.Credentials = new NetworkCredential("Chetan.Patel12@vodafone.com", "Sep@2016@P");

Advice: Never post real credential on public forum.
Change password as fast as possible.
 
Share this answer
 
Comments
Member 12954126 19-Feb-17 23:38pm    
Thanks for suggession...
Email body is HTML - not ASP.NET. Just create a HTML body and add normal <a href="..."> links to your images that lead to your website.
 
Share this answer
 
Comments
Member 12954126 17-Feb-17 9:15am    
i know it is html, but how to send request from anyone's mail and from any browser to direct execute the click event of the buttons in visual studio that i have discussed above?

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