views:

287

answers:

3

I've recently taken over the responsibility of looking after a clients website that has been built in asp.net by an ex-employee. (who left in a hurry to work for said clients!)

The company is going to be moving over to a php platform in the not so distant future but until then they are having some email delivery issues. NOTE: I'm not proficient in asp.net

Now, none of the code on any of this clients websites has been changed recently. We host them on a reseller hosting account with Namesco in the UK.

I believe the issue is with the SMTP server not allowing these emails through. However I can't find where the SMTP address is set in the code?

Some Background info on this clients setup:

They have two websites the main site who's domain ends in .co.uk Then a seperate site who's domain ends in .tv

The .co.uk and .tv code for the sites web forms is exactly the same. The .co.uk emails are coming through but the .tv emails have suddenly stopped.

When a potential customer fills in the web forms and hits send. The script calls on a database which adds in some extra text to the email and adds in a FROM address:

E.g. [email protected] [email protected]

If the FROM: address is changed from the .tv to the .co.uk then the emails sent from the .tv sites webforms do arrive successfully. So to me the issue is that the SMTP server does not like the .tv FROM address anymore?

So the customer is still getting their emails however this messes up some mailbox filtering they had setup. So they want to working as it was doing before.

Here is the code in the aspx.cs file for the contact us page:

  using System;  
  using System.Collections.Generic;  
  using System.Web;  
  using System.Web.UI;  
  using System.Web.UI.WebControls;  
  using System.Data;  
  using System.Data.Sql;  
  using System.Data.SqlClient;  
  using System.Data.SqlTypes;  
  using System.Configuration;  
  using System.Web.Mail;  
  using System.Text;  


 public partial class contactus : System.Web.UI.Page  
 {  
    protected void Page_Load(object sender, EventArgs e)  
   {  
       this.Master.FindControl("divMasterContactForm").Visible = false;  
       this.Master.FindControl("contactFormHeader").Visible = false;  
   }  
   protected void butSubmit_Click(object sender, ImageClickEventArgs e)  
   {  
       string strConnection, strCommand, strPage;  

       strPage = Request.Url.ToString();  
       strConnection = ConfigurationManager.ConnectionStrings["dbString"].ConnectionString;  
       strCommand = "SELECT * FROM [mailOptions] WHERE [url] LIKE 'customerswebsite.tv'";  
       StringBuilder strBody = new StringBuilder();  

       SqlConnection myConnection = new SqlConnection(strConnection);  

       SqlCommand myCommand = new SqlCommand(strCommand);  
       myCommand.Connection = myConnection;  

       myConnection.Open();  

       try  
       {  
           SqlDataReader myReader = myCommand.ExecuteReader();  

           while (myReader.Read())  
           {  

               strBody.Append("<html><body><font face='Arial'><br>");  
               strBody.Append(txtQuery.Text);  
               strBody.Append("<br><br>Regards,<br><br>");  
               strBody.Append(txtFirstName.Text + " " + txtLastName.Text);  
               strBody.Append("<br><br>Telephone number: " + txtPhone.Text);  
               strBody.Append("<br><br>Mobile Number: " + txtMobile.Text);  
               strBody.Append("<br><br>Email Address: <a href=mailto:" + txtEmail.Text + ">" + txtEmail.Text + "</a></font></body></html>");  


               MailMessage msgMail = new MailMessage();  
               msgMail.To = myReader["to"].ToString();  
               msgMail.Bcc = "[email protected]";  
               msgMail.From = myReader["from"].ToString();  
               msgMail.Subject = ddQueryType.SelectedValue + " From: " + txtFirstName.Text + " " + txtLastName.Text + ". Generated from " + myReader["leadSource"].ToString();  
               msgMail.BodyFormat = MailFormat.Html;  
               msgMail.Body = strBody.ToString();  
               //lblConfirmation.Text = strBody.ToString();  
               SmtpMail.Send(msgMail);  

               panForm.Visible = false;  
               panConfirm.Visible = true;  
               lblSubject.Text = ddQueryType.SelectedValue;  
               lblFrom.Text = txtEmail.Text;  
               lblBody.Text = txtQuery.Text;  
               lblFirstName.Text = txtFirstName.Text;  
               lblLastName.Text = txtLastName.Text;  
               lblDate.Text = DateTime.Now.ToLongDateString();  
               lblTime.Text = DateTime.Now.ToShortTimeString();  
           }  
           myReader.Close();  
       }  
       catch  
       {  
           lblConfirmation.Text = "Sorry I broke part way through, please call us instead on the number above.";  
       }  

       myConnection.Close();  
   }  
  }  

Currently my problem is that I can't test or track the path of these emails as I can't find which SMTP server the emails are using? Any help appreciated

+3  A: 

Hi,

There's a good chance the SMTP server details is stored in the web.config file. See if you can find a <system.net> tag within the web.config file.

<system.net>
        <mailSettings>
            <smtp  from="[email protected]">
                <network  host="SMTP.SITE.COM" port="25" userName="[email protected]" password="yourPassword"/>
            </smtp>
        </mailSettings>
    </system.net>
keyboardP
I'll check this out tomorrow morning when I'm in the office. However I'm pretty sure I've searched the web.config file for the word smtp and nothing came back. I'll check again though cheers.
bbacarat
Cool. Failing that, in Visual Studio, click on the ASP.NET configuration button. The icon is the earth and a hammer and is at the top of the Solution Explorer (on the right hand side). This lets you configure your ASP.NET app via a browser (most of the settings simply edit the web.config file for you). You can edit SMTP settings there as well, so if you can't find details in the web.config, take a look there and see if that helps.
keyboardP
Hi There, I've checked the web.config file and there is not <system.net> or a <mailSettings> tag anywhere in the file?I have also gone into Visual Studio and clicked on the ASP.NET configuration button. When I look at the "Configure SMTP Settings" the only option set is the server port? Is this unusual?
bbacarat
Hi. Since the previous dev used web.Mail.SmtpMail instead of System.Net.Mail, if SMTP client hasn't been set, the default is the localhost:`http://msdn.microsoft.com/en-us/library/system.web.mail.smtpmail.smtpserver.aspx` This is why only the server port is mentioned in the 'Configure SMTP Settings'. I should also add, the SmtpMail class is obsolete `http://msdn.microsoft.com/en-us/library/system.web.mail.aspx`. If things continue not to work, you could try using the System.Net.Mail namespace instead.
keyboardP
Thanks for that info. I will check it out.
bbacarat
A: 

You could use a network sniffer such as Wireshark (free) to track SMTP traffic, but make sure you have management permission to use such a tool before downloading/installing/using it: such tools have naughty uses as well as benign ones.

phlip
Thanks for this. Just had a look at their video tutorials whoosh! straight over my head. Will need some strong coffee to get my head round that come monday morning
bbacarat
A: 

Make sure that DNS is not the issue. Does the mail host that is supposed to receive your test email no longer accept mails if a reverse DNS lookup for the sending domain does not list your site, or maybe there is no PTR record?

Coincidentally, I just had the same problem last week. Emails that were sent successfully all of sudden stopped working because the server apparently was gray-listed for these very reasons.

If your app is using a local SMTP server, you will see SMTP errors in the Windows event files.

cdonner
I don't get any errors in sending the mail. They just don't arrive when the database sets the FROM address to [email protected] change this to .co.uk and they come through just fine.
bbacarat
I understand that. The SMTP server will happily queue your mail, but it it is not able to relay it. It cannot report this situation back to the client in a synchronous fashion. In my case, the mails ended up in the (MS) SMTP server's Queue folder and after 24 hours were moved into the badmail folder.
cdonner
Hi cdonner, thanks for your help with this, please can you just clarify your comment (in laymans terms) "Does the mail host that is supposed to receive your test email no loner accept mails if a reverse DNS lookup..." Also how do I work out if the app is using a local SMTP server?
bbacarat
Just a quick update. Speaking to my hosting company they have seen test emails stopped with the error message: "all mx records point to non existant host ..." The domain name is not managed by ourselves they have it with a separate company. Would I need to call them and check whats happened?
bbacarat
Also checking the DNS Zones they use a different Host name in their mx record for the .co.uk domain which might explain why they are getting these emails through
bbacarat