我正在为小型企业设置此表单,因此所有电子邮件都会直接发送到他们的邮件服务器。我输入了正确的信息,并且从网站成功发送邮件,但它永远不会到达他们的邮件服务器。他们的邮件服务器确实在联系表单上给出错误,说5.7.1邮件被内容过滤拒绝为垃圾邮件。如果它没有检测到它将发送的垃圾邮件,但服务器仍然不会收到它。
我是在做错代码还是邮件服务器拒绝它?
C# 使用系统; 使用System.Net.Mail;
public partial class _Emailer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
try
{
string output = "";
MailMessage mail = new MailMessage();
// Replace with your own host address
string hostAddress = "xxx.xxx.xxx.xxx";
// Replaces newlines with br
string message = Request.Form["c_Message"].ToString();
message = message.Replace(Environment.NewLine, "<br />");
output = "<p>Name: " + Request.Form["c_Name"].ToString() + ".</p>";
output += "<p>E-mail: " + Request.Form["c_Email"].ToString() + ".</p>";
output += "<p>Phone: " + Request.Form["c_Phone"].ToString() + ".</p>";
output += "<p>Message: " + message + ".</p>";
mail.From = new MailAddress("xxxxxxx@xxxxxx.org");
mail.To.Add("xxxxxxx@xxxxxxx.org");
mail.Subject = "New e-mail.";
mail.Body = output;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(hostAddress);
smtp.EnableSsl = false;
smtp.Send(mail);
lblOutcome.Text = "E-mail sent successfully.";
}
catch (Exception err)
{
lblOutcome.Text = "There was an exception whilst sending the e-mail: " + err.ToString() + ".";
}
}
}
}
HTML
<asp:label id="lblOutcome" runat="server" />
<form name="contact" method="post" id="cf">
<div id="contactform">
<p><img src="images/required_star.png" alt="Star" /> Required fields for contact form completion</p>
<ol>
<li>
<label for="c_Name" class="required-star">Name:</label>
<input type="text" id="Text1" name="c_Name" placeholder="John Doe" class="required text" minlength="2" value="<% Response.Write(Request.Form["c_Name"]); %>" />
</li>
<li>
<label for="c_Email" class="required-star">Email:</label>
<input type="text" id="Text2" name="c_Email" class="required email text" placeholder="example@domain.com" value="<% Response.Write(Request.Form["c_Email"]); %>" />
</li>
<li>
<label for="c_Phone">Phone:</label>
<input type="text" id="Text3" name="c_Phone" class="phoneUS text" placeholder="ex. (555) 555-5555" value="<% Response.Write(Request.Form["c_Company"]); %>" />
</li>
<li>
<label for="c_Message" class="required-star">Message:</label>
<textarea id="Textarea1" name="c_Message" rows="6" cols="50" class="required" placeholder="..." minlength="2"><% Response.Write(Request.Form["c_Message"]); %></textarea>
</li>
<li class="buttons">
<input title="Submit" class="buttonBlue" value="Submit" type="submit" />
<input title="Clear the form" class="buttonBlue" value="Clear" type="reset" />
</li>
</ol>
</div>
</form>
答案 0 :(得分:0)
看起来这完全取决于过滤电子邮件的邮件服务器。也许联系电子邮件主机并解释您的问题。
答案 1 :(得分:0)
由于很多原因,它可能被视为垃圾邮件。其中之一是来自地址与发送的主机电子邮件不匹配。例如。您从pop3.yourhost.com
发送电子邮件,从字段发送电子邮件为my@name.com
无论如何它似乎与ASP.NET
无关