如何回复引用的HTML消息?

问题描述 投票:0回答:0

我正在阅读 MailKit 常见问题解答如何使用引用的原始消息回复 HTML 消息

它没有解释如何将 your message 和 ReplyVisitor 消息设置到正文。有什么想法吗?

我成功运行了示例代码,但由于我不知道在哪里设置我的 HTML 消息,电子邮件是空白的,只有引用的消息。

public static MimeMessage Reply (MimeMessage message, MailboxAddress from, bool replyToAll)
{
    var visitor = new ReplyVisitor ();
    var reply = new MimeMessage ();

    reply.From.Add (from);

    // reply to the sender of the message
    if (message.ReplyTo.Count > 0) {
        reply.To.AddRange (message.ReplyTo);
    } else if (message.From.Count > 0) {
        reply.To.AddRange (message.From);
    } else if (message.Sender != null) {
        reply.To.Add (message.Sender);
    }

    if (replyToAll) {
        // include all of the other original recipients (removing ourselves from the list)
        reply.To.AddRange (message.To.Mailboxes.Where (x => x.Address != from.Address));
        reply.Cc.AddRange (message.Cc.Mailboxes.Where (x => x.Address != from.Address));
    }

    // set the reply subject
    if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
        reply.Subject = "Re: " + message.Subject;
    else
        reply.Subject = message.Subject;

    // construct the In-Reply-To and References headers
    if (!string.IsNullOrEmpty (message.MessageId)) {
        reply.InReplyTo = message.MessageId;
        foreach (var id in message.References)
            reply.References.Add (id);
        reply.References.Add (message.MessageId);
    }

    visitor.Visit (message);

    // How do I set my own text if this is overridden by the visitor body??
    // var myTextBody = new BodyBuilder();
    // myTextBody.HtmlBody = "<div>HELLO WORLD</div>";
    // reply.Body = myTextBody.ToMessageBody();

    reply.Body = visitor.Body ?? new TextPart ("plain") { Text = ReplyVisitor.GetOnDateSenderWrote (message) + Environment.NewLine };

    return reply;
}
mailkit mimekit
© www.soinside.com 2019 - 2024. All rights reserved.