spamassassin检查得分C#代码

有没有办法检查ASP.Net应用程序的分数? .Net的类或类似的东西? 那里有其他垃圾邮件filter怎么样。 – 编辑我正在寻找一种方法来检查C#中的电子邮件的垃圾邮件分数。

这是我的超级简化的“只检查分数”代码,用于连接到我为http://elasticemail.com写的C#正在运行的Spam Assassin电子邮件检查。 只需设置SA即可在服务器上运行并设置访问权限。

然后你可以使用这段代码来调用它:

public class SimpleSpamAssassin { public class RuleResult { public double Score = 0; public string Rule = ""; public string Description = ""; public RuleResult() { } public RuleResult(string line) { Score = double.Parse(line.Substring(0, line.IndexOf(" ")).Trim()); line = line.Substring(line.IndexOf(" ") + 1); Rule = line.Substring(0, 23).Trim(); Description = line.Substring(23).Trim(); } } public static List GetReport(string serverIP, string message) { string command = "REPORT"; StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} SPAMC/1.2\r\n", command); sb.AppendFormat("Content-Length: {0}\r\n\r\n", message.Length); sb.AppendFormat(message); byte[] messageBuffer = Encoding.ASCII.GetBytes(sb.ToString()); using (Socket spamAssassinSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { spamAssassinSocket.Connect(serverIP, 783); spamAssassinSocket.Send(messageBuffer); spamAssassinSocket.Shutdown(SocketShutdown.Send); int received; string receivedMessage = string.Empty; do { byte[] receiveBuffer = new byte[1024]; received = spamAssassinSocket.Receive(receiveBuffer); receivedMessage += Encoding.ASCII.GetString(receiveBuffer, 0, received); } while (received > 0); spamAssassinSocket.Shutdown(SocketShutdown.Both); return ParseResponse(receivedMessage); } } private static List ParseResponse(string receivedMessage) { //merge line endings receivedMessage = receivedMessage.Replace("\r\n", "\n"); receivedMessage = receivedMessage.Replace("\r", "\n"); string[] lines = receivedMessage.Split('\n'); List results = new List(); bool inReport = false; foreach (string line in lines) { if (inReport) { try { results.Add(new RuleResult(line.Trim())); } catch { //past the end of the report } } if (line.StartsWith("---")) inReport = true; } return results; } } 

用法非常简单:

 List spamCheckResult = SimpleSpamAssassin.GetReport(IP OF SA Server, FULL Email including headers); 

它将返回您点击的垃圾邮件检查规则列表以及由此产生的分数影响。

我不确定这是否是您要搜索的内容,但是有一个C#包装器可以简化与Code Project上的SpamAssassin服务器的通信:

  • SpamAssassin协议的AC#包装器

希望有所帮助!