Search code examples
c#emailiissmtpgmail

sending email (using gmail SMTP) from windows 7 server


There are many threads related to this, and my C# code is below:

public const string REGISTRATION_SMTP_HOST = "smtp.gmail.com ";
public const int REGISTRATION_SMTP_PORT = 465;
public const string REGISTRATION_SMTP_LOGIN = "[email protected]";
public const string REGISTRATION_SMTP_PASSWORD = "----";

// send the email
SmtpClient smtp = new SmtpClient();
smtp.Host = CommonCode.REGISTRATION_SMTP_HOST;
smtp.Port = CommonCode.REGISTRATION_SMTP_PORT;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(CommonCode.REGISTRATION_SMTP_LOGIN,CommonCode.REGISTRATION_SMTP_PASSWORD);
smtp.Timeout = 300000;
smtp.Send(mm);

Running the web application locally from our development Windows 7 boxes, the emails are sent successfully (using port 587). So our gmail credentials are good.

However, when we deploy the application to our server, the gmail SMTP server is failing to respond. We have tried ports 465, 587, and 25...same result.

On the server, we have temporarily turned off Windows Firewall.

From the command line on the server, I can telnet into smpt.gmail.com 25 (but not 587 or 465).

The server's IIS SMTP settings are identical to our local workstations.

We have read every post related to this and nothing seems to be working.

Any help would be greatly appreciated.


Solution

  • We were able to solve the issue by opening the local security policies > IP security policies on local computer > Right click on "packet filter" and click "unassign".

    This worked for us.

    Although this might not be secure. We will look into security to figure out how we can open specific ports on our server.