Is it possible to programmatically 'clean' emails?

后端 未结 6 1072
一向
一向 2021-01-03 08:36

Does anyone have any suggestions as to how I can clean the body of incoming emails? I want to strip out disclaimers, images and maybe any previous email text that may be als

6条回答
  •  执念已碎
    2021-01-03 08:52

    SigParser has an assembly you can use in .NET. It gives you the body back in both HTML and text forms with the rest of the stuff stripped out. If you give it an HTML email it will convert the email to text if you need that.

    var parser = new SigParser.EmailParsing.EmailParser();
    var result = await parser.GetCleanedBodyAsync(new SigParser.EmailParsing.Models.CleanedBodyInput {
        FromEmailAddress = "john.smith@example.com",
        FromName = "John Smith",
        TextBody = @"Hi Mark,
    This is my message.
    
    Thanks
    John Smith
    888-333-4434"
                });
    
    // This would print "Hi Mark,\r\nThis is my message."
    Console.WriteLine(result.CleanedBodyPlain); 
    
    

提交回复
热议问题