Click here to Skip to main content
13,046,281 members (120,361 online)
Rate this:
Please Sign up or sign in to vote.
Hi everyone!

I am creating a forgot password screen for my application for users to reset their passwords. The program is then supposed to send emails with the updated password to the email account associated with the username. The current status is is that the program freezes when it reaches the smtp.send(message) command and eventually times out. I've tried this with the gmail server information and my smtp server here at my work. No email is being sent at all. Does anyone know if this has to do with the code or with an email setting?

Thanks everyone!

MailMessage message = new MailMessage();
message.From = new MailAddress("***");
message.Subject = "New test mail";
message.Body = "Hello test message succeed";
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.ASCII;
message.Priority = System.Net.Mail.MailPriority.High;
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "";
smtp.Credentials = new NetworkCredential("username", "password");
catch (Exception ex)
     throw ex;
Posted 30-Apr-13 5:10am
ProgramFOX 30-Apr-13 11:34am
Is the "username" when you create your NetworkCredential equal to "***" (the From property of your message)?
joshrduncan2012 30-Apr-13 11:41am
No, the username just has to match the email address associated with the account, otherwise, the reset password will fail.
Dave Kreskowiak 30-Apr-13 14:15pm
He's saying that the "username" and "password" should be gmail account that is going to send the email, not the users account that you're changing the password for.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The code LOOKS correct, but without knowing the exception that's thrown, it's difficult to say.

The network credentials must be a valid GMail login name.

Your work server cannot lbokc access to the GMail servers (most corporate networks do!)

You cannot use your GMail email address in the From field if you're going to use your corporate SMTP server. Chances are really good that you must use an address that is valid in your corporate email system.
joshrduncan2012 30-Apr-13 12:15pm
Thanks Dave. The exception I'm getting is a smtp exception (The operation has timed out).
Dave Kreskowiak 30-Apr-13 14:16pm
It's possible that your corporate network is blocking access to GMail.
joshrduncan2012 30-Apr-13 14:19pm
Thanks Dave. I actually got it to work with a gmail address in the from field and my personal credentials in the networkcredential section for testing purposes. Now comes the fun part of deciding what to use since I don't want to send out this program with my personal credentials coded into it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100