0

我正在用 C# 开发一个自定义传输代理。为此,我正在使用 microsoft exhange server 2010。每当收到电子邮件时,我需要根据某些条件决定是否允许发送。如果它不应该被允许,我将整个电子邮件(.eml)作为 blob 存储在数据库中。现在我不想使用数据库来保存被拒绝的电子邮件。我想将这些电子邮件保存在某个邮箱中。我想知道是否可以将电子邮件重定向到邮箱?

4

1 回答 1

0
public class FIMFactory : RoutingAgentFactory

{

public override RoutingAgent CreateAgent(SmtpServer server)
{
    return new FIMAgent(server);
}

}

公共类 FIMAgent : RoutingAgent { 私有只读 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);
}

}

于 2021-10-07T10:08:18.730 回答