Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sending mail through gmail

Sending mail through gmail

Scheduled Pinned Locked Moved C#
csharpsecurityhelpcom
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharpiesharpie
    wrote on last edited by
    #1

    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).

    F 1 Reply Last reply
    0
    • S sharpiesharpie

      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).

      F Offline
      F Offline
      Frank Kerrigan
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • F Frank Kerrigan

        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

        S Offline
        S Offline
        sharpiesharpie
        wrote on last edited by
        #3

        well, so how do i supply a username and password? :\ that's what i'm asking

        C 1 Reply Last reply
        0
        • S sharpiesharpie

          well, so how do i supply a username and password? :\ that's what i'm asking

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups