Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Egidius Bakker   on Aug 05 In Asp.net Category.

  
Question Answered By: Abriana Rossi   on Aug 05

I am having a problem  when I am trying to send an email from my
local host. Here is there error  message I get: The server rejected
one or more recipient addresses. The server response was: 550 5.7.1
Unable to relay for yosefzachbryan@.... I can change the
email address as much as I want but I still get the same error.
Below is the code  I am using. Please let me know what I can do to
fix this problem. Here is the code I am using:


namespace Ww3live
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

/// <summary>
/// Summary description for RegisterUser.
/// </summary>
public class RegisterUser : System.Web.UI.UserControl
{
#region variables
protected System.Web.UI.WebControls.Label
lblUserName;
protected System.Web.UI.WebControls.TextBox
txtUserName;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.Label lblPass;
protected System.Web.UI.WebControls.TextBox txtPass;
protected System.Web.UI.WebControls.Label
lblVerifyPass;
protected System.Web.UI.WebControls.TextBox
txtVerifyPass;
protected System.Web.UI.WebControls.Label
lblBirthYear;
protected System.Web.UI.WebControls.Label
lblBirthDay;
protected System.Web.UI.WebControls.Label
lblBirthMonth;
protected System.Web.UI.WebControls.Label lblEmail;
protected System.Web.UI.WebControls.DropDownList
ddlYear;
protected System.Web.UI.WebControls.DropDownList
ddlDay;
protected System.Web.UI.WebControls.DropDownList
ddlMonth;
protected System.Web.UI.WebControls.Button
btnRegister;
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvUserName;
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvEmail;
protected
System.Web.UI.WebControls.RegularExpressionValidator revEmail;
protected
System.Web.UI.WebControls.ValidationSummary vsError;
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvPass;
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvVerifyPass;
int year;
protected System.Web.UI.WebControls.CompareValidator
cvPass;
protected
System.Web.UI.WebControls.RegularExpressionValidator revUserName;
protected
System.Web.UI.WebControls.RegularExpressionValidator revPass;
protected
System.Web.UI.WebControls.RegularExpressionValidator revVerifyPass;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand
sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand
sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand
sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection
sqlConnection1;
protected System.Data.SqlClient.SqlDataAdapter
sqlDataAdapter1;
string test;
#endregion

private void Page_Load(object sender,
System.EventArgs e)
{
// Put user code to initialize the page here
FillYears();
FillDays();
FillMonths();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the
ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer
support - do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.btnRegister.Click += new
System.EventHandler(this.btnRegister_Click);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT
PlayerId, PlayerName, PlayerEmail, PlayerPass, PlayerBirth FROM
tblPlayer";
this.sqlSelectCommand1.Connection =
this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT
INTO tblPlayer(PlayerName, PlayerEmail, PlayerPass, PlayerBirth)
VALUES (@" +
"PlayerName, @PlayerEmail,
@PlayerPass, @PlayerBirth); SELECT PlayerId, PlayerNam" +
"e, PlayerEmail, PlayerPass,
PlayerBirth FROM tblPlayer WHERE (PlayerId = @@IDENT" +
"ITY)";
this.sqlInsertCommand1.Connection =
this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerName",
System.Data.SqlDbType.VarChar, 50, "PlayerName"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerEmail",
System.Data.SqlDbType.VarChar, 100, "PlayerEmail"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerPass",
System.Data.SqlDbType.VarChar, 50, "PlayerPass"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerBirth",
System.Data.SqlDbType.DateTime, 4, "PlayerBirth"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText =
@"UPDATE tblPlayer SET PlayerName = @PlayerName, PlayerEmail =
@PlayerEmail, PlayerPass = @PlayerPass, PlayerBirth = @PlayerBirth
WHERE (PlayerId = @Original_PlayerId) AND (PlayerBirth =
@Original_PlayerBirth) AND (PlayerEmail = @Original_PlayerEmail) AND
(PlayerName = @Original_PlayerName) AND (PlayerPass =
@Original_PlayerPass); SELECT PlayerId, PlayerName, PlayerEmail,
PlayerPass, PlayerBirth FROM tblPlayer WHERE (PlayerId = @PlayerId)";
this.sqlUpdateCommand1.Connection =
this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerName",
System.Data.SqlDbType.VarChar, 50, "PlayerName"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerEmail",
System.Data.SqlDbType.VarChar, 100, "PlayerEmail"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerPass",
System.Data.SqlDbType.VarChar, 50, "PlayerPass"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerBirth",
System.Data.SqlDbType.DateTime, 4, "PlayerBirth"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "PlayerId",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerBirth",
System.Data.SqlDbType.DateTime, 4,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerBirth",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerEmail",
System.Data.SqlDbType.VarChar, 100,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerEmail",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerName",
System.Data.SqlDbType.VarChar, 50,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerName",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerPass",
System.Data.SqlDbType.VarChar, 50,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerPass",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@PlayerId",
System.Data.SqlDbType.Int, 4, "PlayerId"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE
FROM tblPlayer WHERE (PlayerId = @Original_PlayerId) AND
(PlayerBirth = @O" +
"riginal_PlayerBirth) AND
(PlayerEmail = @Original_PlayerEmail) AND (PlayerName =" +
" @Original_PlayerName) AND
(PlayerPass = @Original_PlayerPass)";
this.sqlDeleteCommand1.Connection =
this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "PlayerId",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerBirth",
System.Data.SqlDbType.DateTime, 4,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerBirth",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerEmail",
System.Data.SqlDbType.VarChar, 100,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerEmail",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerName",
System.Data.SqlDbType.VarChar, 50,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerName",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_PlayerPass",
System.Data.SqlDbType.VarChar, 50,
System.Data.ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "PlayerPass",
System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString
= "workstation id=HOME;packet size=4096;integrated
security=SSPI;data source=HOME;pe" +
"rsist security info=False;initial
catalog=ww3live";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand =
this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand =
this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand =
this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange
(new System.Data.Common.DataTableMapping[] {



new System.Data.Common.DataTableMapping
("Table", "tblPlayer", new System.Data.Common.DataColumnMapping[] {






new
System.Data.Common.DataColumnMapping("PlayerId", "PlayerId"),






new
System.Data.Common.DataColumnMapping("PlayerName", "PlayerName"),






new
System.Data.Common.DataColumnMapping("PlayerEmail", "PlayerEmail"),






new
System.Data.Common.DataColumnMapping("PlayerPass", "PlayerPass"),






new
System.Data.Common.DataColumnMapping
("PlayerBirth", "PlayerBirth")})});
this.sqlDataAdapter1.UpdateCommand =
this.sqlUpdateCommand1;
this.Load += new System.EventHandler
(this.Page_Load);

}
#endregion

public int GetYear()
{
year = int.Parse
(System.DateTime.Now.Year.ToString());
return year;
}

public void FillYears()
{
int temp = GetYear() - 100;
for(int i = temp; i <= GetYear(); i++)
{
ddlYear.Items.Add(i.ToString());
ddlYear.DataBind();
}
}

public void FillDays()
{
for(int i = 1; i <= 31; i++)
{
ddlDay.Items.Add(i.ToString());
ddlDay.DataBind();
}
}

public void FillMonths()
{
for(int i = 1; i <= 12; i++)
{
ddlMonth.Items.Add(i.ToString());
ddlMonth.DataBind();
}
}

private void btnRegister_Click(object sender,
System.EventArgs e)
{
test = string.Empty;

SqlCommand uName = new SqlCommand();
uName.Connection = sqlConnection1;
uName.CommandType =
CommandType.StoredProcedure;
uName.CommandText = "sp_FindEmail";
uName.Parameters.Add(new SqlParameter
("@Email", SqlDbType.VarChar, 100));
uName.Parameters["@Email"].Value =
txtEmail.Text;
sqlConnection1.Open();

try
{
test = uName.ExecuteScalar().ToString
();
lblMessage.Text = "This email
already exists, please choice another email address.";
}
catch(NullReferenceException nre)
{
string error = nre.Message;
test = string.Empty;
}

if(test == string.Empty)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection1;
cmd.CommandType =
CommandType.StoredProcedure;
cmd.CommandText = "sp_FindUser";
cmd.Parameters.Add(new SqlParameter
("@uName", SqlDbType.VarChar, 50));
cmd.Parameters["@uName"].Value =
txtUserName.Text;

try
{
test = cmd.ExecuteScalar
().ToString();
lblMessage.Text = "This
player name already exists, please choice another name.";
}
catch(NullReferenceException nre)
{
string error = nre.Message;
test = string.Empty;
}

sqlConnection1.Close();

if(test == string.Empty)
{
RegisterPlayer();
}
}
}

public void RegisterPlayer()
{
lblMessage.Text = string.Empty;
string playerBirth =
ddlMonth.SelectedItem.Text + "/" +
ddlDay.SelectedItem.Text + "/" +
ddlYear.SelectedItem.Text;
register player = new register
(txtUserName.Text, txtEmail.Text,
txtPass.Text, playerBirth);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection1;
cmd.CommandType =
CommandType.StoredProcedure;
cmd.CommandText = "sp_AddUser";

cmd.Parameters.Add(new SqlParameter
("@pName", SqlDbType.VarChar, 50));
cmd.Parameters["@pName"].Value =
player.UserName;
cmd.Parameters.Add(new SqlParameter
("@pEmail", SqlDbType.VarChar, 100));
cmd.Parameters["@pEmail"].Value =
player.Email;
cmd.Parameters.Add(new SqlParameter
("@pPass", SqlDbType.VarChar, 50));
cmd.Parameters["@pPass"].Value = player.Pass;
cmd.Parameters.Add(new SqlParameter
("@pBirth", SqlDbType.SmallDateTime));
cmd.Parameters["@pBirth"].Value =
player.BirthDay;
sqlConnection1.Open();

try
{
cmd.ExecuteNonQuery();

SendEmail();
lblMessage.Text = player.UserName
+ " is now registered under " +
player.Email + ". Please
wait for the verification letter" +
" to activate your account.";
}
catch(System.Exception err)
{
Response.Write(err.Message);
}
finally
{
ClearFields();
sqlConnection1.Close();
}
}

public void ClearFields()
{
txtEmail.Text = "";
txtPass.Text = "";
txtUserName.Text = "";
txtVerifyPass.Text = "";
ddlDay.SelectedIndex = 0;
ddlMonth.SelectedIndex = 0;
ddlYear.SelectedIndex = 0;
}

public void SendEmail()
{
Server.ScriptTimeout = 1000;
Response.Flush();

MailMessage mail  = new MailMessage();
SmtpMail.SmtpServer = "localhost";
mail.To = txtEmail.Text;
mail.From = "admin@...";
mail.Subject = "WW3Live.com Activation
Validation";
mail.Body = "Welcome to WW3Live.com!<br>" +
"Your User Name is: " + txtUserName.Text
+ "<br><br>" +
"Your Password is: " + txtPass.Text
+ "<br><br>" +
"To activate your account, please click
the " +
"following link.";
mail.BodyEncoding =
System.Text.Encoding.GetEncoding( "GB2312" );

try
{
SmtpMail.Send(mail.From, mail.To,
mail.Subject, mail.Body);
Response.Write("The Mail has been
sent to: ");
Response.Write(mail.To);
Response.Write(mail.Body);
}
catch(System.Exception msg)
{
Response.Write(msg.Message);
}
Response.Flush();
}
}
}




Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on SMTP mail problem Or get search suggestion and latest updates.


Tagged: