Venkata Subbareddy

Venkata Subbareddy

  • 997
  • 770
  • 99.3k

How to send the Mails in Godady server

Jun 6 2015 12:58 AM
 Hi All,
 
i am Developing School management Project in Asp.net and sql server.
 Description:
When New User Registration on my site , the details will go Admin Approve Forms Will Data base, When Admin Approve the  New student  , the student Will get UserName And Password. this process working Perfectly in my Local System. The Same Code  upload the  Godady server the user not getten  username and password let me know Any one iam Doing Wrong Any Ware. in the Below I just  share the Source 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.Data.SqlClient;
using System.Net;
using System.Net.Mail;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Text;
public partial class AdminAcceptstudents : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=198.71.226.6;Initial Catalog=ritsindia_MuraliIIT;User ID=Rits;Password=rits@1234");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind_Data();
}
private void Bind_Data()
{
SqlConnection conn = new SqlConnection("Data Source=198.71.226.6;Initial Catalog=ritsindia_MuraliIIT;User ID=RITS;Password=rits@1234");
string s = "select * from NewStudentRegistrationForm ORDER BY Userid DESC; ";
//SqlCommand cmd = new SqlCommand("s, conn");
SqlDataAdapter da = new SqlDataAdapter(s, conn);
//cmd.CommandType = CommandType.Text;
DataSet ds = new DataSet();
da.Fill(ds, "NewStudentRegistrationForm");
GvApproveStudent.DataSource = ds.Tables[0];
GvApproveStudent.DataBind();
}
public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
{
CheckBox chkStatus = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
string UserId = row.Cells[7].Text;
bool ApproveStatus = chkStatus.Checked;
string constr = @"Data Source=198.71.226.6;Initial Catalog=ritsindia_MuraliIIT;User ID=RITS;Password=rits@1234";
string query = "UPDATE NewStudentRegistrationForm SET ApproveStatus = @ApproveStatus WHERE UserId = @UserId";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.Text;
com.Parameters.Add("@ApproveStatus", SqlDbType.Bit).Value = ApproveStatus;
com.Parameters.Add("@UserId", SqlDbType.Char).Value = UserId;
com.ExecuteNonQuery();
}
private static bool SendEmail(string fromEmail, string toEmail, string subject, string content, string userName, string password, string smtpServer, int portNumber)
{
bool isSent = false;
try
{
MailMessage msg = new MailMessage(fromEmail, toEmail, subject, content);
msg.IsBodyHtml = true;
var smtp = new SmtpClient(smtpServer)
{
Port = portNumber,
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(userName, password)
};
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
smtp.Send(msg);
isSent = true;
}
catch (Exception ex)
{
}
return isSent;
}
protected void btnSelectUserSendTheDetails_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (GridViewRow row in GvApproveStudent.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkStatus = (CheckBox)row.Cells[18].FindControl("chkStatus");
if (chkStatus != null && chkStatus.Checked)
{
string UserId = row.Cells[7].Text;
string password = row.Cells[8].Text;
string EmailAddress = row.Cells[11].Text;
chkStatus.Text = "Approved";
bool ApproveStatus = chkStatus.Checked;
string constr = @"Data Source=198.71.226.6;Initial Catalog=ritsindia_MuraliIIT;User ID=RITS;Password=rits@1234";
string query = "UPDATE NewStudentRegistrationForm SET ApproveStatus = @ApproveStatus WHERE UserId = @UserId";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.Text;
com.Parameters.Add("@ApproveStatus", SqlDbType.Bit).Value = ApproveStatus;
com.Parameters.Add("@UserId", SqlDbType.Char).Value = UserId;
com.ExecuteNonQuery();
con.Close();
sb.Append("Please check below data <br/><br/>");
sb.Append("Hi,<br/>Your Username is: " + UserId + "<br/><br/>Your Password is: " + password + "<br/>");
bool result = SendEmail("[email protected]", EmailAddress, "Hello", sb.ToString(), " [email protected]", "rits@1234", "relay-hosting.secureserver.net", 25);
}
}
Bind_Data();
}
}
}
 

Answers (4)