|
-
May 1st, 2009, 11:02 AM
#1
Thread Starter
Junior Member
[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 ^^
-
May 1st, 2009, 11:25 AM
#2
Hyperactive Member
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:
Dim emailClient As New SmtpClient(strMailServer)
emailClient.Credentials = (SMTP_Cred)
emailClient.DeliveryMethod = SmtpDeliveryMethod.Network
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.
-
May 1st, 2009, 01:16 PM
#3
Thread Starter
Junior Member
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.
-
May 1st, 2009, 04:58 PM
#4
Thread Starter
Junior Member
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.
-
May 1st, 2009, 06:49 PM
#5
New Member
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.
-
May 1st, 2009, 07:15 PM
#6
Thread Starter
Junior Member
Re: Using SMTPClient with GMail
Got it working!!
Used this code:
vb Code:
Dim MySMTPClient As New Net.Mail.SmtpClient
With MySMTPClient
.Port = 587
.Host = "smtp.gmail.com"
.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
.EnableSsl = True
.Timeout = 30000
End With
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!!
-
May 2nd, 2009, 07:24 AM
#7
New Member
Re: [RESOLVED] Using SMTPClient with GMail
Good to hear.
But don't you get an error on this line?
Something about "recipient.text" not being a valid mailaddress?
-
May 2nd, 2009, 09:19 PM
#8
Thread Starter
Junior Member
Re: [RESOLVED] Using SMTPClient with GMail
 Originally Posted by EightsOver
Good to hear.
But don't you get an error on this line?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|