Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using (MailMessage mm = new MailMessage("my email", txtEmail.Text))
{
mm.Subject = "تفيل الحساب";
string body = "مرحبا ";

mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
//smtp.Host = "smtp.gmail.com";

smtp.UseDefaultCredentials = false;
NetworkCredential NetworkCred = new NetworkCredential("my email ", "<my password="">");

smtp.Credentials = NetworkCred;
smtp.EnableSsl = true;
smtp.Port = 587;// 465;
smtp.Send(mm);
}
Posted

This problem is just with the network credentials you're passing alongwith the MailMessage object, first thing to check is whether your credentials (username and password combination) are correct as per server you're using; the username and password is correct for the Gmail server.

There are some past questions that you might be interested in reading to learn more on this problem, and you will finding interesting that all of them have the same problem, that include, Ssl to be enabled, username/password combination to be correct, or the port number to be correct.

Sending email using Gmail[^]
Smtp mail throuws an error[^]

Chances are you will find a perfect conclusion to this problem from these answers. Anyways, I would to suggest one more thing to you, to test before going further to read these answers. Which is to change the port to 25; if you're sure that the username/password combination is correct.
 
Share this answer
 
this code helps u.i this so.don't forget to change email-id and password .check it out.textBox1.Text for emailID and textBox2.Text for password

MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string from = "YOUR MAIL-ID";
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(textBox1.Text);
message.Subject = textBox2.Text;
message.IsBodyHtml = true;



message.Body = richTextBox1.Text;
smtpClient.Port = 587;
smtpClient.Host = "smtp.gmail.com";
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("YOUR MAILID", " YOUR PASSWORD");
smtpClient.EnableSsl = true;
smtpClient.Send(message);
message.Dispose();
MessageBox.Show("Email Send Successfully ....");
}

catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
 
Share this answer
 
Comments
Member 11166005 28-Feb-15 2:26am    
if this is your answer then give me 5 star Mr.ddtrko
Hai,

Can u refer this link..

a) go to gmail security center via this link blow or google search for “gmail secrity” and login with your gmail account
click here

b)next to “security” / “Recent activity” , click to “view all events”

c)You will able to see “Unusual Activity” , it will show all unusual activity events, select related event and approval it via click ” Yes, That was me!”

d)https://accounts.google.com/DisplayUnlockCaptcha[^]//Click allow access to your Google account

e)You have to enable login from other timezone / ip for your google account.

f)go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps[^] and enable less secure apps . So that you will be able to login from all apps.
 
Share this answer
 
v2
Creditentials used are incorrect, please check and enter the correct credentials
 
Share this answer
 

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