Click here to Skip to main content
14,601,157 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi i have an error,
i have written a code to send an email.
the email was sent to private email address
like info@yourdomain.com

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("mail.mydomain.com", 25);
MailMessage Msg = new MailMessage();
//------for Email Data----------------------------------
Msg.To.Add(TxtEmail .Text .Trim ());
Msg.From = new MailAddress("tehnical@mydomain.com");

Msg.IsBodyHtml = true;

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

MaxUserIdDa.Fill(MaxUserIdDs);
MaxUserIdCon.Close();
 
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: ");
bodyMsg.Append("

Activate Your Account");
 
Msg.Body = bodyMsg.ToString();
 
//authentication--------------------------------------------------------------------------------
SmtpClient mySmtpClient = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("tehnical@mydomain.com", "password");
mySmtpClient.Host = "mail.mydomain.com";
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = myCredential;

//-------------------------------------------------------------------------------------------
mySmtpClient.Send(Msg);
LblMessage.Text = "An email for account verification has been sent,please check your email";
EmptyTextBoxes();

// ------for Email Data----------------------------------
}
Posted
Updated 18-Jul-12 22:21pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

[edit]
And this is the second time you have posted it in Q&A.
[/edit]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100