Sending mail through gmail
-
I'm trying to send a mail through gmail using System.Net.Mail..but it's giving me errors. here's the code:
MailMessage msg = new MailMessage(); msg.From = new MailAddress("jiminyjones@gmail.com"); msg.To.Add("sharpie@usmarines.com"); msg.Subject = "C# Mail Message!"; msg.Body = "Hey Buddy!"; msg.IsBodyHtml = false; SmtpClient b = new SmtpClient(); b.Host = "smtp.google.com"; b.Send(msg);
I know the problem is with the authentication because gmail requires ssl, but i couldn't find a way to fix it (i tried "b.EnableSsl = true" but it didn't work). -
I'm trying to send a mail through gmail using System.Net.Mail..but it's giving me errors. here's the code:
MailMessage msg = new MailMessage(); msg.From = new MailAddress("jiminyjones@gmail.com"); msg.To.Add("sharpie@usmarines.com"); msg.Subject = "C# Mail Message!"; msg.Body = "Hey Buddy!"; msg.IsBodyHtml = false; SmtpClient b = new SmtpClient(); b.Host = "smtp.google.com"; b.Send(msg);
I know the problem is with the authentication because gmail requires ssl, but i couldn't find a way to fix it (i tried "b.EnableSsl = true" but it didn't work).I don't think gmail has an open SMTP relay. You are not supplying a username or password for the smtp server to authenicate you.
Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http:\\www.frankkerrigan.com
-
I don't think gmail has an open SMTP relay. You are not supplying a username or password for the smtp server to authenicate you.
Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http:\\www.frankkerrigan.com
well, so how do i supply a username and password? :\ that's what i'm asking
-
well, so how do i supply a username and password? :\ that's what i'm asking
Well, if you look up the documentation for the SmtpClient[^] class you'll see you can specify Credentials[^]. You get the credentials from the CredentialCache[^] or you can create your own NetworkCredential[^] like this[^]
Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos