3

Possible Duplicate:
Sending email in .NET through Gmail

I tried sending e-mail with Gmail SMTP and System.Net.Mail as follows:

        Dim objSMTPClient As New System.Net.Mail.SmtpClient("smtp.gmail.com", 465) 'also tried 587
        objSMTPClient.EnableSsl = True
        objSMTPClient.UseDefaultCredentials = False
        objSMTPClient.Credentials = New System.Net.NetworkCredential("email@domain.com", "password")
        objSMTPClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
        objSMTPClient.Send(objMailMessage)

However, when I try port 465, I get an exception "The operation has timed out." And when I try port 587, I get the exception "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at "

Any idea why?

Thanks in advance.

UPDATE: The problem seems to have solved itself as of tonight. I don't know what changed. Perhaps something on the Google side. In any case, the code is working; I'd love to know what was wrong so I can make sure it does not happen again, and also to help the community, but I can't get it into the not-working state so I can try things and test it.

ALSO: I beg to differ with the moderator who marked my question as a duplicate of another thread -- that thread simply asked generically how to send mail via Gmail. I read that thread, and was doing everything it said to do, but it didn't work for me, so I posted error messages and asked what was wrong.

I would like to point readers to this other thread which is actually closer to being my duplicate, and which I couldn't find earlier, and which has numerous possible suggestions which could possibly have helped, except that the problem is gone now so I can't test it. Thanks all!

Community
  • 1
  • 1
Fred
  • 185
  • 1
  • 12
  • Perhaps access via SMTP was temporarily blocked due to suspicious activity. See http://stackoverflow.com/questions/1607828/how-to-use-gmail-as-a-free-smtp-server-and-overcome-captcha – Greg Apr 10 '11 at 05:19

2 Answers2

0

Most probably, your credentials are incorrect. Note that you have to use valid active gmail account, so it would be in the form of:

objSMTPClient.Credentials = New System.Net.NetworkCredential("<your_user_name>@gmail.com", "<your_gmail_password>");
VinayC
  • 47,395
  • 5
  • 59
  • 72
  • The credentials are correct; I just logged in with them. – Fred Apr 08 '11 at 06:14
  • I should say, this is not a regular Gmail account but a Google Apps account. When I try my code with my regular Gmail account it *works*; it's only with the Google Apps account that it does not. – Fred Apr 08 '11 at 06:16
  • @Fred, at such this shouldn't be an issue - see http://mail.google.com/support/bin/answer.py?answer=78799. Why don't you try configuring account in some mail client such as outlook with same settings. – VinayC Apr 08 '11 at 07:54
0

Most probably,you have not enabled pop features in your gmail account.If you want to use gmail smtp features then this option should be enabled.

enter image description here

santosh singh
  • 27,666
  • 26
  • 83
  • 129
  • Thanks, but POP is enabled. What could be the problem? – Fred Apr 08 '11 at 06:13
  • I should add that this is not a regular Gmail account but a Google Apps account. When I try my code with my regular Gmail account it *works*; it's only with the Google Apps account that it does not. – Fred Apr 08 '11 at 06:14