Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send email with username not email address
code:
C#
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("mohsin.paracha44@gmail.com");
mail.To.Add("mohsin_paracha02@yahoo.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("Mohsin Paracha", "convents");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
Label1.Text="mail Send";


its not working
Posted
Updated 10-Feb-12 20:12pm
v2
Comments
Michel [mjbohn] 11-Feb-12 2:12am    
pre tag added
OriginalGriff 11-Feb-12 3:00am    
"its not working" is not very helpful.
What is it doing that it shouldn't, or not doing that it should?
Use the "Improve question" widget to edit your question and provide better information.

You can't send mail via gMail using a username for authentication.
You have to use your gmail address and password to log in.

new System.Net.NetworkCredential("yourgooglemailname@gmail.com", "yourPassword");

Probably "@gmail.com" might be omitted.


regards
Michel
 
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