SMTP Works from Visual Studio Debugging, Not on Published Web Site

Discussion in 'Email' started by GroverparkGeorge, Mar 2, 2015.

  1. Up until just recently, the following code worked correctly in a page on my website. It STILL works correctly when I run it in debug mode from Visual Studio. When I publish the page, it no longer works. This makes no sense to me.

    protectedvoid btnSubmit_Click(object sender, EventArgs e)

    {
    try
    {
    MailMessage msg = newMailMessage();
    SmtpClient smtp = newSmtpClient("mail.MYDOMAIN.com");
    MailAddress fromAddress = newMailAddress("[email protected]", "Inquiry From the web page");
    MailAddress toAddress = newMailAddress("[email protected]", "To Sales and Service");
    msg.To.Add(toAddress);
    msg.From = fromAddress;
    msg.IsBodyHtml = true;
    msg.Subject = "A request FROM: " + txtName.Text + " Regarding: " + txtSubject.Text;
    if (txtAttachmentPath.HasFile)
    {
    string FileName = System.IO.Path.GetFileName(txtAttachmentPath.PostedFile.FileName);
    msg.Attachments.Add(newAttachment(txtAttachmentPath.PostedFile.InputStream, FileName));
    }
    msg.Body = " Email: " + txtEmail.Text + ". <br/ > Phone: " + txtPhone.Text + ". <br /> Message submitted: " + txtMessage.Text;
    conststring fromPassword = "MYPASSWORD";
    smtp.Port = 587;
    smtp.EnableSsl = false;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword);
    //Send the msg
    smtp.Send(msg);
    //Display feedback to the user to let them know it was sent

    lblResult.Text = "Your request was sent ";

    //Clear the form
    txtName.Text = "";
    txtMessage.Text = "";
    txtSubject.Text = "";
    txtEmail.Text = "";
    txtPhone.Text = "";
    }
    catch
    {
    //If the message failed at some point, let the user know
    lblResult.Text = "Your message failed to send, please try again.";
    }
    }


    I changed from port 25 to 587. Again, that works fine in VS on the desktop, but not in the web site.

    What am I missing?

    Thanks
     
    Last edited: Mar 2, 2015
  2. I've been able to determine that the problem is with my ISP, which is not only blocking port 25, but also port 587, apparently. So, I'm screwed until I figure out an alternative to smtp.
     
  3. Sorry to hear that George, it used to be unusual for an ISP to block alternative ports, but unfortunately it's becoming more common. We appreciate you posting the follow up though.
     
  4. I tried five different email accounts, none of which worked. I am forced to conclude it's the ISP blocking the ports. Still, though, I find it odd that I can send correctly from LocalHost in Visual Studio. That makes me wonder if I can make an end run to get to that option from the web page. :D
     
    Last edited: Mar 3, 2015
  5. Oh, and I case anyone is interested, this is Comcast Xfinity residential service. I understand I can switch to a more expensive business service--with slower connections. <sigh>
     
  6. My condolences. ;)
     
    ComputerMan likes this.

Share This Page