1

My application is windows service that send and get messages from mailbox. Emails are saved in the SQL Server database. Now my application send actual text/html (previous emails text is not included in sending message). I want to add possibility to send email with previous emails text/html. Does mailkit or smtp have feature which will help me to implement this mechanism or I should I collect data about every email and construct text/html by myself.

I want to send emails this way

Now I send emails this way

Here is my example of sending email:

var mimeMessage = new MimeMessage();
var multipart = new Multipart("mixed");

mimeMessage.To.AddRange(GetListOfMailboxAddresses(row.Field<int?>("ToGroup")) ?? new List<MailboxAddress>());
mimeMessage.Cc.AddRange(GetListOfMailboxAddresses(row.Field<int?>("CcGroup")) ?? new List<MailboxAddress>());
mimeMessage.Bcc.AddRange(GetListOfMailboxAddresses(row.Field<int?>("BccGroup")) ?? new List<MailboxAddress>());
mimeMessage.From.Add(new MailboxAddress(row["FromName"].ToString(), PluginHelper.ConfigurationXML.SmtpKonfig.SmtpUzytkownik));
mimeMessage.Sender = new MailboxAddress(row["FromName"].ToString(), PluginHelper.ConfigurationXML.SmtpKonfig.SmtpUzytkownik);

mimeMessage.Subject = row["Subject"].ToString();
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = row["HTML"].ToString();
bodyBuilder.TextBody = row["Text"].ToString();
multipart.Add(bodyBuilder.ToMessageBody());
var attachment = new MimePart();

if (Convert.ToInt32(row["SendingEmailId"]) == (int)EmailSendingType.Reply)
{
    if (!mimeMessage.Subject.StartsWith("Re:", StringComparison.OrdinalIgnoreCase))
        mimeMessage.Subject = "Re:" + mimeMessage.Subject;

    ConstructReplyReferences(DataAccess.GetGuidsForReply(Convert.ToInt32(row["ConversationId"]), Convert.ToInt32(row["Id"])), row["ReplyToGuid"].ToString(), mimeMessage);
    try
    {
        ConstructReplyReferencesFromCREW(row.Field<int?>("ObjectNumber"), mimeMessage);
    }
    catch (Exception ex)
    {
        LoggerHelper.LogInfo(ex.ToString());
    }
}

if (!string.IsNullOrWhiteSpace(row.Field<string>("ReplyEmailInUserWindow")))
{
    mimeMessage.ReplyTo.Clear();
    mimeMessage.ReplyTo.Add(new MailboxAddress(row.Field<string>("ReplyEmailInUserWindow")));
}

GetAddAttachments(multipart, Convert.ToInt32(row["Id"]));

mimeMessage.Body = multipart;

client.Send(mimeMessage);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3210023
  • 164
  • 13
  • 1
    One possible solution might be [quote original message](https://stackoverflow.com/questions/31460653/quote-original-message-in-a-reply-using-mailkit) – Ardit May 07 '19 at 11:46

0 Answers0