kiran kumar

kiran kumar

  • NA
  • 1k
  • 270.5k

error--mailbox unavailable

Dec 16 2009 6:55 PM
when i try to send mail an exception was raised "mail box unavailable" this is my code protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { MembershipUser newuser = Membership.GetUser(CreateUserWizard1.UserName); Guid newuserid = (Guid)newuser.ProviderUserKey; SqlConnection con = new SqlConnection("Data Source=KIRAN\\SQLEXPRESS;Initial Catalog=kiran;Integrated Security=True"); con.Open(); string querystring; querystring = "insert into reg(username,password,email,securityquestion,securityanswer,userid)values(@username,@password,@email,@securityquestion,@securityanswer,@userid)"; SqlCommand cmd = new SqlCommand(querystring, con); SqlParameter uname = new SqlParameter("@UserName", SqlDbType.NVarChar, 50); uname.Value = CreateUserWizard1.UserName; cmd.Parameters.Add(uname); SqlParameter pass = new SqlParameter("@Password", SqlDbType.NVarChar, 50); pass.Value = CreateUserWizard1.Password; cmd.Parameters.Add(pass); SqlParameter ema = new SqlParameter("@Email", SqlDbType.NVarChar, 50); ema.Value = CreateUserWizard1.Email; cmd.Parameters.Add(ema); SqlParameter secques = new SqlParameter("@securityanswer", SqlDbType.NVarChar, 50); secques.Value = CreateUserWizard1.Question; cmd.Parameters.Add(secques); SqlParameter secans = new SqlParameter("@securityquestion", SqlDbType.NVarChar, 50); secans.Value = CreateUserWizard1.Answer; cmd.Parameters.Add(secans); SqlParameter uid = new SqlParameter("@userid", SqlDbType.NVarChar, 50); uid.Value = newuserid.ToString(); cmd.Parameters.Add(uid); cmd.ExecuteNonQuery(); con.Close(); kiransendmail obj = new kiransendmail(); obj.SendMail(CreateUserWizard1.UserName, CreateUserWizard1.Password, CreateUserWizard1.Email); } public class kiransendmail { System.Net.Mail.SmtpClient smtpConnection; public kiransendmail() { smtpConnection = new System.Net.Mail.SmtpClient(); smtpConnection.Host = "kiran";//Your mail server's ip or name. smtpConnection.Port = 25;//The port smtpConnection.Credentials = new System.Net.NetworkCredential("kiran", "kumar");//Username and password to access mail server } public void SendMail(string Username, string password, string email) { string mailbody = String.Format("This is your account details. Username: {0}, Password: {1}", Username, password); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add(email); message.Subject = "Your account details"; message.From = new System.Net.Mail.MailAddress("[email protected]");//Give your from e mail address here message.Body = mailbody; smtpConnection.Send(message); } } } and my to add is [email protected] i am using default smtp server on iis Mailbox unavailable. The server response was: 5.7.1 Unable to relay for [email protected] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for [email protected] Line 73: message.From = new System.Net.Mail.MailAddress("[email protected]");//Give your from e mail address here message.Body = mailbody; smtpConnection.Send(message); }

Answers (5)