2011-11-10 114 views
2

我從我的ASP.net Web應用程序發送電子郵件。C#.Net消息將發送到垃圾郵件文件夾

郵件成功發送失敗,但大多數都是垃圾郵件文件夾。

請幫我過來垃圾郵件過濾器。

我發送郵件代碼

public void SendMail(string FromAddress, string ToAddress, string Subject, string BodyText) 
    { 
     MailMessage mailMsg = new MailMessage(); 

     mailMsg.From = new MailAddress(FromAddress,"My Name"); 
     mailMsg.To.Add(new MailAddress(ToAddress)); 
     mailMsg.Subject = Subject; 
     mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8"); 

     System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString 
     (System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain"); 
     System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText, null, "text/html"); 

     mailMsg.AlternateViews.Add(plainView); 
     mailMsg.AlternateViews.Add(htmlView); 

     // Smtp configuration 
     SmtpClient smtp = new SmtpClient(); 
     smtp.Host = "smtp.mysite.com"; 

     smtp.Credentials = new System.Net.NetworkCredential(FromAddress, "password"); 
     smtp.EnableSsl = false; 
     try 
     { 
      smtp.Send(mailMsg); 
     } 
     catch (Exception ex) 
     { 

      throw ex; 
     } 
    } 
+2

我懷疑這與.NET或C#有什麼關係。這些消息的內容是什麼? –

+0

同意:這與內容有關。當我查看代碼時,內容似乎爲空... – Jan

+1

您是否查看了垃圾郵件文件夾中郵件的標題?可能會添加分類標題,解釋爲什麼它被標記爲垃圾郵件。您是否從具有有效的現有電子郵件域的電子郵件地址發送郵件? –

回答

6

一兩件事,突出的是,你永遠不會定身。我會刪除此行:

// Remove the html alternate view 
mailMsg.AlternateViews.Add(htmlView); 

並嘗試以下(未經測試):

// Set the html view to be the default view, leaving the plain text view as the only alternative view 
mailMsg.IsBodyHtml = true; 
mailMsg.Body = htmlView; 
+0

這不會幫助保持郵件不在垃圾郵件文件夾中。相反,相反。 –

+0

@DanielFischer,在某種意義上是正確的。這一切都取決於消息的內容。雖然(我認爲)沒有設置身體不會對情況有所幫助, –

4

郵件經常被標記爲垃圾郵件由於受特殊的話,發送者的域名或的內容郵件或附件。所以我認爲它與發送機制(如c#或.NET)沒有任何關係。

1

有很多原因可能會將您的電子郵件標記爲垃圾郵件。 This是如何儘量避免您的電子郵件被標記爲垃圾郵件的好名單。根據我的經驗,儘管使用AuthSMTP等服務反而更加不利。

相關問題