1

I need to process raw email messages and pull out the To and From addresses. I could just search for 'To: ' but I'd rather do this in a structured way to avoid issues.

How can I build a MIME message from raw email text, then get the To/From headers?

I've seen MimeKit used for sending emails before but don't seem to be able to find a way to hydrate MimeKit message object from a raw string so I can pull out the To/From headers. I get this runtime error if I just try passing raw email text into the constructor:

Exception: System.ArgumentException: Unknown initialization parameter: System.String at MimeKit.MimeMessage..ctor(Object[] args) at AWSS3Test.Services.CallS3.ListingObjectsAsync() 

Google has returned nothing of use.

It doesn't have to be MIMEKit, but how can I do this?

2
  • 1
    Have you seen the documentation? github.com/jstedfast/MimeKit#parsing-messages You'll have to either wrap your message with a stream or read it directly from disk Commented Dec 11, 2020 at 10:34
  • Your link didn't work but you set me on the right track thanks. I'll answer my own question, needs to be a stream and use Load method not constructor. Commented Dec 11, 2020 at 10:51

1 Answer 1

2

It needs to use .Load not the constructor and string needs to be converted to a stream

var message = new MimeMessage(); byte[] byteArray = Encoding.ASCII.GetBytes(TestEmail); MemoryStream stream = new MemoryStream(byteArray); message = MimeMessage.Load(stream); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.