Click here to Skip to main content
15,120,078 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi i have an error,
i have written a code to send an email.
the email was sent to private email address

but the email was not sent to any
"gmail or yahoo mail address."

when i tried to sent an email to gmail or yahoo account the following error occurs,

"Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server."

here is my code :
protected void SendEmail()
SmtpClient smtpClient = new SmtpClient("", 25);
MailMessage Msg = new MailMessage();
//------for Email Data----------------------------------
Msg.To.Add(TxtEmail .Text .Trim ());
Msg.From = new MailAddress("");

Msg.IsBodyHtml = true;

//----Get Max userid------------------------------
string strConnection = ConfigurationManager.ConnectionStrings["AIGamesConnectionString"].ConnectionString;
SqlConnection MaxUserIdCon = new SqlConnection(strConnection);
string StrMaxUserId = "select max(id) as Id from users";
SqlCommand MaxUserIdComm = new SqlCommand(StrMaxUserId, MaxUserIdCon);
SqlDataAdapter MaxUserIdDa = new SqlDataAdapter(MaxUserIdComm);
DataSet MaxUserIdDs = new DataSet();

int MaxUserId=1;
if (MaxUserIdDs.Tables [0].Rows.Count >0)
MaxUserId = Convert.ToInt32(MaxUserIdDs.Tables [0].Rows [0]["Id"].ToString ());
StringBuilder bodyMsg = new StringBuilder();
bodyMsg.Append("Thank you for creating your account.\n\nPlease follow this link to activate: ");

Activate Your Account");
Msg.Body = bodyMsg.ToString();
SmtpClient mySmtpClient = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("", "password");
mySmtpClient.Host = "";
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = myCredential;

LblMessage.Text = "An email for account verification has been sent,please check your email";

// ------for Email Data----------------------------------
Updated 18-Jul-12 23:21pm

1 solution

Please do not post the same question in multiple forums; you already have this question here[^].

And this is the second time you have posted it in Q&A.

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