I found this code on c-sharpcorner.com, it works, untill now i have a lot of problems when i have to send mail using gmail acount. It works, the base source is think big blog's; enjoy it!
// C# Code
MailMessage msg = new MailMessage();
// Your mail address and display name.
// This what will appear on the From field.
// If you used another credentials to access the SMTP server, the mail message would be
// sent from the mail specified in the From field on behalf of the real sender.
msg.From = new MailAddress("example-mail@gmail.com", "PAN");
// To addresses
msg.To.Add(new MailAddress("x@example.com", "b0by"));
msg.To.Add(new MailAddress("x@example.com", "me"));
// You can specify CC and BCC addresses also
// Set to high priority
msg.Priority = MailPriority.High;
msg.Subject = "Hey, a fabulous site!";
// You can specify a plain text or HTML contents
msg.Body = "Hello everybody,<br /><br />" +
"I found an interesting site called <a href=\"http://pan-internet.com\">" +
"Pan Internet!</a>. Be sure to visit it soon.";
// In order for the mail client to interpret message body correctly,
// we mark the body as HTML because we set the body to HTML contents.
msg.IsBodyHtml = true;
// Attaching some data; throws an exception if the file does not exist
//msg.Attachments.Add(new Attachment("C:\\Site.lnk"));
// Connecting to the server and configuring it
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 25;
client.EnableSsl = true;
// The server requires user's credentials not the default credentials
client.UseDefaultCredentials = false;
// Provide your credentials
client.Credentials = new System.Net.NetworkCredential("example-mail@gmail.com", "examplepasssword");
// Use SendAsync to send the message asynchronously
try
{
client.Send(msg);
}
catch (SmtpFailedRecipientException e1)
{
Console.WriteLine(e1.Message);
//SmtpFailedRecipientException
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
95b5619f-743f-45db-96d3-90f8764ef499|0|.0