如何保护 在 asp.net 中将发送的电子邮件归类为垃圾邮件
本文关键字:电子邮件 保护 何保护 net asp | 更新日期: 2023-09-27 18:30:30
可能的重复项:
如何降低电子邮件的垃圾邮件分数?
我有这个 c# 代码,可以向人们发送大量电子邮件。 但是我发送的电子邮件已被归类为垃圾邮件。我该怎么办 .我应该对我的代码应用任何更改吗?我尝试从sql服务器数据库获取电子邮件地址,我的代码可以附加一个文件。
Entities context = new Entities();
var query = from c in context.Emails select c.EmailAddress;
MailMessage mail = new MailMessage();
Regex sample = new Regex(@"^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~]('.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*
@[a-zA-Z](-?[a-zA-Z0-9])*('.[a-zA-Z](-?[a-zA-Z0-9])*)+$");
int total = 0;//number of all emails
int count = 0;//counter for putting interrupt between each 10 sending
int failed = 0;//number of failed sending
int success = 0;//number of successful sending
double totalsize = 0;//size of attachment file
if (FileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
foreach (Attachment attachment in mail.Attachments)
{
string size =attachment.ContentStream.Length.ToString ();
totalsize=Convert .ToDouble (size);
}
}
foreach (var c in query)
{
if (count == 10)
{
Thread.Sleep(10000);
count = 0;
}
mail.From = new MailAddress("hadi@myhost.com");
mail.Bcc.Add(new MailAddress(c.ToString()));
mail.Subject = "hello";
mail.IsBodyHtml = true;
mail.Body = FCKeditor1.Value.ToString();
SmtpClient smtp = new SmtpClient();
smtp.Host = "localhost";
smtp.Port = 25;
if ((sample.IsMatch(c.ToString())) && (sample .IsMatch (mail .From .ToString ())) && (totalsize<1000000))
{
try
{
smtp.Send(mail);
//Response.Write("email has sent to " + c.ToString());
success++;
}
catch
{
//Response.Write("email has not sent to " + c.ToString());
failed++;
}
count++;
}
total++;
}
您无需对代码执行任何操作即可使其不是垃圾邮件。您所要做的就是确保您从不应该具有"开放中继"的主机发送电子邮件,这意味着不是每个人都可以从中发送电子邮件。
从正确的服务器并使用正确的电子邮件签名发送电子邮件,以便当收件人检查身份验证时,他们应该对您的电子邮件源服务器进行身份验证,并从您的电子邮件主机验证签名。