Results 1 to 8 of 8

Thread: [RESOLVED] Using SMTPClient with GMail

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    25

    Resolved [RESOLVED] Using SMTPClient with GMail

    Hi everybody.

    I'm trying to send an email with the SMTPClient through a GMail account, but I'm having the problem that once I press the Send Button, the app freezes and I'm not getting any email.

    I've looked around but I found nothing that is specifically made for Gmail.

    The code I'm using is this one:

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
            Dim MySMTPClient As New Net.Mail.SmtpClient
            With MySMTPClient
                .Port = 465
                .Host = "smtp.gmail.com"
                .DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
                .EnableSsl = True
                .Timeout = 30
                .Credentials = New Net.NetworkCredential("[email protected]", "*****", "[email protected]")
            End With
            MySMTPClient.Send("[email protected]", "recipient.text", "Subject", "Body")
        End Sub
    It hasn't got much, but I want to get the mailing part working first.

    Thanks a lot ^^

  2. #2
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Using SMTPClient with GMail

    This is a cut and paste from a code block that I use to send email through GMail.
    VB Code:
    1. Dim emailClient As New SmtpClient(strMailServer)
    2.             emailClient.Credentials = (SMTP_Cred)
    3.             emailClient.DeliveryMethod = SmtpDeliveryMethod.Network
    4.             emailClient.EnableSsl = True

    At the top of the page I have:

    Dim SMTP_Cred As New System.Net.NetworkCredential("[email protected]", "password"). Actualy now that I look at the code side by side it looks as though yours should work. What is the error you are getting or is it just freezing?

    You may want to step though it with the debugger and see if it makes it all the way through or find out where it is freezing.
    Last edited by FastEddie; May 1st, 2009 at 11:30 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    25

    Re: Using SMTPClient with GMail

    I've just tried using your version, the app just freezes.

    I've stepped through all the code, no errors appeared.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    25

    Re: Using SMTPClient with GMail

    I tried the same with AOL, still not working.
    The following error appeared here: "Syntax error, command unrecognized. The server response was: CLIENT AUTHENTICATION REQUIRED. USE ESMTP EHLO AND AUTH."

    I used another version of the smtp client which uses the sendasync command, and it's getting the same error.


    Does anyone know a free e-mail service that actually works with this?
    Last edited by KaDMiO; May 1st, 2009 at 05:12 PM.

  5. #5
    New Member
    Join Date
    Apr 2009
    Location
    Sweden
    Posts
    4

    Re: Using SMTPClient with GMail

    Hi.

    Don't have a definite answer to why it isn't working but it seems to be related to the use of port 465. I've used roughly the same code with ISP's who are using port 587 - and then it is working fine. After I read this I tested it with Google and port 465 and it hangs for me too. I do get a timeout eventually though...
    No trace in my firewall logs that it even tries to connect to the server.
    Looks like smtpClient isn't too keen on using that port. Even if you skip both credentials and SSL the same thing happens. Anyone have any more info on this?

    As it looks it is possible to use port 587 with GMail... Not sure if they are happy about it and if it is supported though.

    A few notes on your code btw;
    - Isn't the timeout value a bit short (It's in milliseconds)?
    - There are some quotes that shouldn't be in your MySMTPClient.Send... But I think you'll notice as soon as you get the current problem fixed.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    25

    Re: Using SMTPClient with GMail

    Got it working!!

    Used this code:

    vb Code:
    1. Dim MySMTPClient As New Net.Mail.SmtpClient
    2.         With MySMTPClient
    3.             .Port = 587
    4.             .Host = "smtp.gmail.com"
    5.             .DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
    6.             .EnableSsl = True
    7.             .Timeout = 30000
    8.             .Credentials = New Net.NetworkCredential("[email protected]", "password")
    9.         End With
    10.         MySMTPClient.Send("[email protected]", "recipient.text", "Subject", "Body")

    The port number was the problem, I'm glad it goes now.
    Now that I'm able to send emails, let's make it perfect.

    Thanks a lot!!

  7. #7
    New Member
    Join Date
    Apr 2009
    Location
    Sweden
    Posts
    4

    Re: [RESOLVED] Using SMTPClient with GMail

    Good to hear.

    But don't you get an error on this line?
    Code:
    MySMTPClient.Send("[email protected]", "recipient.text", "Subject", "Body")
    Something about "recipient.text" not being a valid mailaddress?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    25

    Re: [RESOLVED] Using SMTPClient with GMail

    Quote Originally Posted by EightsOver View Post
    Good to hear.

    But don't you get an error on this line?
    Code:
    MySMTPClient.Send("[email protected]", "recipient.text", "Subject", "Body")
    Something about "recipient.text" not being a valid mailaddress?
    recipient.text is just to remind me that there has to go the email address of the recipient, I know it isn't like that. Sorry for the confusion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width