Hi
The below code working fine but I dont want to pass the username and pwd at NetworkCredential. Is there any way to avoid passing username and password ? Is it mandatory that we should pass from username and password in NetworkCredential ?
SmtpClient _SmtpClient = new SmtpClient("smtp.gmail.com");
MailAddressCollection _MailAddressCollection = new MailAddressCollection();
MailMessage _message = new MailMessage();
_message.From = new MailAddress("abc@gmail.com");
_message.Body = "Body of the mail";
_message.Subject = "Sending mail from c# Code";
_message.To.Add("sat@gmail.com");
Attachment data = new Attachment("D:\\Attachement.xls");
_message.Attachments.Add(data);
_SmtpClient.Port = 587;
_SmtpClient.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "pwd");
_SmtpClient.UseDefaultCredentials = true;
_SmtpClient.EnableSsl = true;
_SmtpClient.Send(_message);
System.Console.ForegroundColor = ConsoleColor.Green;
System.Console.WriteLine("Email Has Been Sent...");
System.Console.Read();