我正在c#中开发一个自定义传输代理。我使用的是微软exchange server 2010。每当一封邮件来的时候,我需要根据一些条件来决定它是否应该允许去。如果它不应该被允许去我存储整个电子邮件(. email) blob在数据库中。现在我不想使用数据库持有拒绝的电子邮件。我想把那些邮件放在某个邮箱里。我想知道是否可以将电子邮件重定向到邮箱?
public class FIMFactory : RoutingAgentFactory
{
public override RoutingAgent CreateAgent(SmtpServer server)
{
return new FIMAgent(server);
}
}
公共类FIMAgent: RoutingAgent{private readonly SmtpServer _server;
public FIMAgent(SmtpServer server)
{
_server = server ?? throw new ArgumentNullException(nameof(server));
OnResolvedMessage += FIMAgent_OnResolvedMessage;
}
private void FIMAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
{
var mi = e.MailItem;
var emailMessage = EmailMessage.Create(BodyFormat.Text, false, "utf-8");
emailMessage.Sender = new EmailRecipient(mi.Message.Sender.DisplayName, mi.Message.Sender.SmtpAddress);
emailMessage.To.Add(new EmailRecipient(mi.Message.Sender.DisplayName, mi.Message.Sender.SmtpAddress));
emailMessage.Subject = "...";
using (var stream1 = emailMessage.Body.GetContentWriteStream())
using (var sw = new StreamWriter(stream1, new UTF8Encoding(false)))
{
sw.WriteLine("...");
}
_server.SubmitMessage(emailMessage);
}
}