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. noreply@customersite.tv noreply@customersite.co.uk
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 = "info@ourwebdesignfirm.com";
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.Cl开发者_如何学Cose();
}
}
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
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="user@domain.com">
<network host="SMTP.SITE.COM" port="25" userName="name@domain.com" password="yourPassword"/>
</smtp>
</mailSettings>
</system.net>
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.
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.
精彩评论