try this no need to any settings.
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );
newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";
Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );
SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "urmail@gmail.com", "urpwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
<pre>