error--mailbox unavailable
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); }
Nilanka DharmadasaPosted Dec 17, 2009, 12:33 AM
If you want to send your e mail through your gmail account, change your code as follows.
public class kiransendmail
{
System.Net.Mail.SmtpClient smtpConnection;
public kiransendmail()
{
smtpConnection = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtpConnection.Port = 587;//The port
smtpConnection.UseDefaultCredentials = false;
smtpConnection.EnableSsl = true;
smtpConnection.Credentials = new System.Net.NetworkCredential("[email protected]", "your gmail password");//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);
}
}
Try this and let me know.
If you find this helpful, please check 'Do you like this answer' checkbox.
kiran kumarPosted Dec 17, 2009, 2:12 AM
Nilanka DharmadasaPosted Dec 17, 2009, 1:47 AM
Happy to hear that.
Anyway if it helped you please check 'Do you like this answer' check box near my reply. It helps mea lot.
kiran kumarPosted Dec 17, 2009, 1:16 AM
Lalit MPosted Dec 17, 2009, 12:13 AM
more info